You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ben Kim <bk...@coe.tamu.edu> on 2005/09/20 15:39:44 UTC
RE: Resizing JPEG Images
Wonder if this fits your needs, but ginp uses something similar.
http://culnane.navidat.com/dc/ginp/index.jsp
Features
- Thumbnails are created and stored on the file system.
- Pictures are sized to the browser window size to reduce bandwidth.
Regards,
Ben Kim
Developer
http://benix.tamu.edu
-----Original Message-----
From: Justin Jaynes [mailto:justinjaynesresearch@yahoo.com]
Sent: 20 September 2005 04:29
To: tomcat-user@jakarta.apache.org
Subject: Resizing JPEG Images
I am accepting JPEG uploads on a website I developed in JSP and Java Beans.
It all runs on Tomcat.
I once knew of a Java Bean that would accept a JPEG and scale and resize the
image and save it. I need my web-app to resize the images as it accpets
them.
That was years ago. I can't find it any longer. Does anyone know how or
where I should start? If writing my own bean would be easy using some part
of the Enterprise Java SDK, please point me in the right direction and I'll
do the work.
I am using the lates version of the JDK.
Thanks,
Justin
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Resizing JPEG Images
Posted by Derek Conniffe <de...@rivertower.ie>.
Hi Justin,
I've written beans like that many times (image resizing, cropping,
etc). Its a doddle with JAI. If you want some code examples email me.
Derek
Ben Kim wrote:
>Wonder if this fits your needs, but ginp uses something similar.
>
>http://culnane.navidat.com/dc/ginp/index.jsp
>
>Features
>- Thumbnails are created and stored on the file system.
>- Pictures are sized to the browser window size to reduce bandwidth.
>
>
>Regards,
>
>Ben Kim
>Developer
>http://benix.tamu.edu
>
>-----Original Message-----
>From: Justin Jaynes [mailto:justinjaynesresearch@yahoo.com]
>Sent: 20 September 2005 04:29
>To: tomcat-user@jakarta.apache.org
>Subject: Resizing JPEG Images
>
>I am accepting JPEG uploads on a website I developed in JSP and Java Beans.
>It all runs on Tomcat.
>
>I once knew of a Java Bean that would accept a JPEG and scale and resize the
>image and save it. I need my web-app to resize the images as it accpets
>them.
>
>That was years ago. I can't find it any longer. Does anyone know how or
>where I should start? If writing my own bean would be easy using some part
>of the Enterprise Java SDK, please point me in the right direction and I'll
>do the work.
>
>I am using the lates version of the JDK.
>
>Thanks,
>
>Justin
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
--
Derek Conniffe
Rivertower Ltd
Ireland: (Freephone) 1800 719 400
Ireland: (Local) 01 244 9719
United Kingdom: 0870 068 2368
International: 00 353 1 244 9719
Derek Conniffe DDI: 01 201 0146 (International: 00 353 1 201 0146)
Derek Conniffe Mobile: 086 856 3823 (International: 00 353 86 856 3823)
Fax: 01 201 0085 (International: 00 353 1 201 0085)
Email: Derek@rivertower.ie
Web: http://www.rivertowerhosting.com
Re: Resizing JPEG Images
Posted by Michael Wirz <mi...@abs.de>.
Hello,
This is what I use for the given problem.
I found it on the web and it fits my needs, so perhaps you'd like to use
it as well
Best wishes from near Munich, Germany,
Michael Wirz
import com.sun.image.codec.jpeg.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
public class Thumbnail {
public static void resize(String infile, String outfile, int
thumbHeight, int quality) throws Exception
{
System.out.println("Thumbnail.resize "+infile+" "+outfile+"
"+thumbHeight+" "+quality);
// load image from INFILE
Image image = Toolkit.getDefaultToolkit().getImage(infile);
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(image, 0);
mediaTracker.waitForID(0);
// determine thumbnail size from WIDTH and HEIGHT
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);
double imageRatio = (double) imageWidth / (double) imageHeight;
int thumbWidth = (int) ((double) thumbHeight * (double) imageRatio);
// draw original image to thumbnail image object and
// scale it to the new size on-the-fly
BufferedImage thumbImage = new BufferedImage(thumbWidth,
thumbHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
// save thumbnail image to OUTFILE
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(outfile));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.
getDefaultJPEGEncodeParam(thumbImage);
quality = Math.max(0, Math.min(quality, 100));
param.setQuality((float)quality / 100.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
out.close();
System.out.println("Done.");
}
public static void main(String[] args)
{
if (args.length != 4)
{
System.err.println("Usage: java Thumbnail INFILE OUTFILE HEIGHT
QUALITY");
System.exit(1);
}
try
{
resize(args[0], args[1], Integer.parseInt(args[2]),
Integer.parseInt(args[3]));
}
catch(Exception e)
{
e.printStackTrace();
}
System.exit(0);
}
}
>Wonder if this fits your needs, but ginp uses something similar.
>
>http://culnane.navidat.com/dc/ginp/index.jsp
>
>Features
>- Thumbnails are created and stored on the file system.
>- Pictures are sized to the browser window size to reduce bandwidth.
>
>
>Regards,
>
>Ben Kim
>Developer
>http://benix.tamu.edu
>
>-----Original Message-----
>From: Justin Jaynes [mailto:justinjaynesresearch@yahoo.com]
>Sent: 20 September 2005 04:29
>To: tomcat-user@jakarta.apache.org
>Subject: Resizing JPEG Images
>
>I am accepting JPEG uploads on a website I developed in JSP and Java Beans.
>It all runs on Tomcat.
>
>I once knew of a Java Bean that would accept a JPEG and scale and resize the
>image and save it. I need my web-app to resize the images as it accpets
>them.
>
>That was years ago. I can't find it any longer. Does anyone know how or
>where I should start? If writing my own bean would be easy using some part
>of the Enterprise Java SDK, please point me in the right direction and I'll
>do the work.
>
>I am using the lates version of the JDK.
>
>Thanks,
>
>Justin
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
--
abs IT Service GmbH
abs Gruppe
Michael Wirz
Entwicklung
Landsberger Straße 57
82266 Stegen am Ammersee
Telefon: +49 (0)8143 999 43
Telefax: +49 (0)8143 999 49
Michael.Wirz@abs.de
www.eFonds24.de
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org