This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

JSP Image Thumbnailer  RSS feed

 
Ma New
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66186
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!