cancel
Showing results for 
Search instead for 
Did you mean: 

Generating images (GIF) from iViews

Former Member
0 Kudos
74

Hi,

I am looking for a way to generate GIF images from my iView.

If I use a regular servlet as a portal component and set the response type to "image/gif", I get an empty HTML page.

Another approach would be to use a normal AbstractPortalComponent. But it seems that an AbstractPortalComponent can only produce HTML/XML/RSS.. output, but no binary format.

To include images as IResources works for static files, but not for Portal Components. Of course it would work to save my image to a file and use that, but I want to avoid that approach.

Has anybody done something like this ?

Regards,

Heiko

Accepted Solutions (1)

Accepted Solutions (1)

dmitryjirov
Explorer
0 Kudos

Hello Heiko,

If you want to create an image in AbstractPortalComponent you can do the following:

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response){

HttpServletResponse servletResponse = request.getServletResponse(false);

servletResponse.setContentType("image/gif");

OutputStream os = servletResponse.getOutputStream();

byte[] gifbytes;

BufferedOutputStream out = null;

try{

gifbytes= <get byte array of the GIF image>;

out = new BufferedOutputStream(os);

out.write(gifbytes);

}finally{

if (os!=null){

os.close();

}

}

}

basically the same approach will work with a plain servlet code.

Best Regards,

Dmitry

Former Member
0 Kudos

Hi Dmitry,

thanks for your answer. I'll try it out but I doubt that it will work: I have tried the same with a regular servlet that I upload, but when I test that as a portal component, I only get an empty HTML page as a response.

That seems consistent to me: I have the impression that Portal Components are expected to only produce text-output and not binary content. But I'll try it out according to your recommendation and post my results.

Cheers,

Heiko

detlev_beutner
Active Contributor
0 Kudos

Hi Heiko,

use an AbstractPortalComponent but implement your content provider within doOnNodeReady. For details also see and

Hope it helps

Detlev

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Detlev, your too fast, remember the speed of light limitation! I think one should have

request.getServletResponse(true)

since you don't want the portal to add any stuff around your Image.

Hope that helps.

PD

detlev_beutner
Active Contributor
0 Kudos

Hi PD,

that's right, but that's also mentioned within the referred thread(s).

Not sure if this is enough, for some reason I have learned to use doOnNodeReady for doContent could be too late in the request cycle.

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

hi PD,

thanks for your comments. It works fine now (reward points already granted ).

I was so focused on doContent() and setComponentResponseType() that I didn't notice that the request-event-cycle is much more complicated (and powerful !). Your hint opened the door to a new area to explore.....

Cheers,

Heiko