How to name on the fly image & performance

I am making a photoalbum and some albums must be private so i put the album_images main folder outside tomcat and i am calling and redrawing images via servlet...my code is below and i have 2 questions?

1)This code gets the image from the target and redraws it via servlet and prints to requested page...if we think 1000 requests at the same time can a 2 gb ram with dual core processor server can handle it without errors?please check my code...i need a general idea about performance..

2)Because of i have printed it with a servlet request(not a direct image src)...for example image src seems like src="print_image?image_id=105" when user right click an image,image name seem as "print_image?image_id=105.jpg" , but i want the image seem as like DSC54534.JPG, is it possible...

Image image = Toolkit.getDefaultToolkit().getImage(ImagePhysicallPath);

MediaTracker mediaTracker =new MediaTracker(new Container());

mediaTracker.addImage(image, 0);

mediaTracker.waitForID(0);

response.reset();

ServletOutputStream cikti=response.getOutputStream();

BufferedImage servletImage=new BufferedImage(500,375,BufferedImage.TYPE_INT_RGB);

Graphics2D graf=(Graphics2D) servletImage.getGraphics();

graf.drawImage(image, 0, 0, 500, 375,null);

JPEGImageEncoder enkoder=JPEGCodec.createJPEGEncoder(cikti);

JPEGEncodeParam param = enkoder.getDefaultJPEGEncodeParam(servletImage);

int quality =100;

quality = Math.max(0, Math.min(quality, 100));

param.setQuality((float)quality / 100.0f,false);

enkoder.setJPEGEncodeParam(param);

enkoder.encode(servletImage);

cikti.close();

thanks for any valueable help

[1948 byte] By [netsonicca] at [2007-10-3 1:02:10]
# 1
please help if u can
netsonicca at 2007-7-14 17:58:17 > top of Java-index,Java Essentials,Java Programming...
# 2

You read and decode the images, which is a) expensive and b) unnecessary, as the browser will have to do this anyway. I'd think about creating a single, small servlet to handle image calls: map information (e.g. a parameter as you described or a pathInfo extra information appended to the URL) to the physical file, set Content-Type to "image/jpeg", set Content-Length, open a FileInputStream and just stream all bytes to the ServletOutputStream without generating any other output.

quittea at 2007-7-14 17:58:17 > top of Java-index,Java Essentials,Java Programming...
# 3

You are absolutely right and thank you...

I am using the above code for resizing and show images on the fly if they are toowide and long...for example resizing from 2048*1578 to 500*375

but for thumbnails i ve used your code directly gets thumbnail from source fileinputstream and writes it to servletoutputstream...

thank you again

Note:I havent set any content type or content size but my code worked....?what is that for.?is it necessary?

netsonicca at 2007-7-14 17:58:17 > top of Java-index,Java Essentials,Java Programming...
# 4

> I am using the above code for resizing and show

> images on the fly if they are toowide and

> long...for example resizing from 2048*1578 to

> 500*375

I would think about a way of caching/saving these thumbnails at least temporarily on disk in order to save time and memory.

> Note:I havent set any content type or content size

> but my code worked....?what is that for.?is it

> necessary?

Most browsers are tolerant enough to work without. The Content-Type gives a hint about how to interpret the data, and Content-Length about the number of data bytes to expect. Browsers may have a guess about the media type anyway (e.g. by looking at file extensions or magic bytes), and the length may also be absent under certain conditions according to HTTP, so you probably don't have to worry. Setting this information helps and doesn't cost a lot.

quittea at 2007-7-14 17:58:17 > top of Java-index,Java Essentials,Java Programming...