Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP Image Thumbnailer

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi I am trying to create a very simple image thumbnailer in JSP such as:

Get imageX.png
Reduce 65 pixels X 65 pixels
Output imageXthumb.png

I have read through a million different documents and have seen a million different ways to do this. I know that I need it to be able to read jpg, gif, and png files, which apparently means I need to user the javax.imageIO.* . I know most people would suggest doing this with a servlet but my boss says I have to do it with JSP so if there is anyone out there who can direct to a good resource or who has some code I can look at I would really appreciate it.

I have checked:

http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html

I have tried to piece together a little JSP app from this info but I cant seem to get problems with the bufferedImage not being recognized in my netbeans. I then looked for other code online and found this which doesn't work either:

<%@ page import="java.io.*" %>
<%@ page import="java.io.File" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.awt.image.*" %>
<%@ page import="javax.imageio.*" %>
<%@ page import="javax.imageio.IIOImage" %>
<%@ page import="javax.imageio.ImageIO" %>
<%@ page import="javax.imageio.ImageIO.*" %>
<%@ page import="javax.imageio.ImageIO.getReaderFormatNames"%>
<%@ page import="javax.imageio.ImageIO.getImageReadersBySuffix"%>

<%
ImageWriter writer;
BufferedImage im = new BufferedImage("/image.jpg");

int tw = im.getWidth() / 5;
int th = im.getHeight() / 5;
BufferedImage thumb = new BufferedImage(tw, th);
Graphics2D g2D = thumb.createGraphics();
g2D.drawImage(im, 0, 0, tw, th, null);

List thumbnails = new ArrayList(1);
thumbnails.add(thumb);

// IoImage holds image, thumbnail, metadata

IIOImage iioim = new IIOImage(im, thumbnails, null);
writer.write(iioim);
%>

If some one could please help me I would be extremely appreciative
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic