commons-user mailing list archives

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

-Shawn

-----Original Message-----
From: Martin Grogan [mailto:mgrogan@mobilegolfers.net]
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,
Martin

String contentType = item.getContentType();
                out.println(contentType);
                if(contentType.equals("image/pjpeg"))
                {
                    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 = 
thumbImage.createGraphics();
                    graphics2D.setRenderingHint(java.awt.RenderingHints.KEY_INTERPOLATION,java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                    graphics2D.drawImage(image, 0, 0, thumbWidth, 
thumbHeight, null);
                    String newfilename=thisuser+"_"+thistime+".jpg";
                    BufferedOutputStream outfile = new 
BufferedOutputStream(new FileOutputStream("c:\\"+newfilename));
                    JPEGImageEncoder encoder = 
JPEGCodec.createJPEGEncoder(outfile);
                    JPEGEncodeParam param = 
encoder.getDefaultJPEGEncodeParam(thumbImage);
                    int quality = 100;
                    param.setQuality((float)quality / 100.0f, false);
                    encoder.setJPEGEncodeParam(param);
                    encoder.encode(thumbImage);
                    outfile.close();
                }

---------------------
----- Original Message ----- 
From: "Stefan Rufer" <stefan.rufer@netcetera.ch>
To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
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 
>uploading.
>
> 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.
>   http://forum.java.sun.com/thread.jspa?threadID=177124&messageID=554105
> as starting point.
>
> cu
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message