commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernard, Shawn" <>
Subject RE: [FileUpload] Resizing JPEG before upload
Date Thu, 02 Jun 2005 13:26:33 GMT
Another solution is to use something like ImageMagick ( which gives
you a ton of image-related functionality in addition to image resizing.


-----Original Message-----
From: Martin Grogan []
Sent: Thursday, June 02, 2005 8:54 AM
To: Jakarta Commons Users List
Subject: Re: [FileUpload] Resizing JPEG before upload

Here's the code, for resizing JPEG images after they are uploaded, for 
anyone that's interested.
Only the relevant portions shown, hope it will be of use to some people.
All the best,

String contentType = item.getContentType();
                    File uploadedFile = new File("output.jpg");
                    ImageIcon myImageIcon = new ImageIcon(item.get());
                    java.awt.Image image = myImageIcon.getImage();
                    // attempt to code jpeg
                    int thumbWidth=150;
                    int thumbHeight=100;
                    BufferedImage thumbImage = new BufferedImage(thumbWidth, 
thumbHeight, BufferedImage.TYPE_INT_RGB);
                    java.awt.Graphics2D graphics2D = 
                    graphics2D.drawImage(image, 0, 0, thumbWidth, 
thumbHeight, null);
                    String newfilename=thisuser+"_"+thistime+".jpg";
                    BufferedOutputStream outfile = new 
BufferedOutputStream(new FileOutputStream("c:\\"+newfilename));
                    JPEGImageEncoder encoder = 
                    JPEGEncodeParam param = 
                    int quality = 100;
                    param.setQuality((float)quality / 100.0f, false);

----- Original Message ----- 
From: "Stefan Rufer" <>
To: "Jakarta Commons Users List" <>
Sent: Thursday, June 02, 2005 10:59 AM
Subject: Re: [FileUpload] Resizing JPEG before upload

>I don't know if I got you right, but you can not resize the JPEG before 
> You have to upload the whole JPEG to the server and do the resize there. 
> For this check out Java Advanced Imaging I guess, e.g.
> as starting point.
> cu
> Stefan
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message