1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.geocities.com/kpdus/jad.html
3 // Decompiler options: packimports(3)
4 // Source File Name: ImageConverter.java
9 import java.awt.image.*;
10 import org.ibex.util.*;
12 import javax.servlet.*;
13 import javax.servlet.http.*;
15 public class ImageConverter extends HttpServlet {
17 public ImageConverter() { }
19 public void init(ServletConfig servletconfig) { cx = servletconfig.getServletContext(); }
20 public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
21 throws IOException, ServletException { doGet(httpservletrequest, httpservletresponse); }
23 public void doGet(HttpServletRequest req, HttpServletResponse resp)
24 throws IOException, ServletException {
26 if (req.getServletPath().indexOf("..") != -1) throw new IOException(".. not allowed in image paths");
27 String s = cx.getRealPath(req.getServletPath());
28 String s1 = s.indexOf('.') != -1 ? s.substring(0, s.lastIndexOf('.')) : s;
29 File file = new File((new StringBuilder()).append(s1).append(".png").toString());
30 if (!file.exists()) file = new File((new StringBuilder()).append(s1).append(".psd").toString());
31 if (!file.exists()) file = new File((new StringBuilder()).append(s1).append(".gif").toString());
32 if (!file.exists()) file = new File((new StringBuilder()).append(s1).append(".jpeg").toString());
33 if (file.getAbsolutePath().endsWith(".gif")) {
34 resp.setContentType("image/gif");
36 resp.getOutputStream().write(InputStreamToByteArray.convert(new FileInputStream(file)));
37 } else if (file.getAbsolutePath().endsWith(".jpeg")) {
38 resp.setContentType("image/jpeg");
40 resp.getOutputStream().write(InputStreamToByteArray.convert(new FileInputStream(file)));
41 } else if (file.getAbsolutePath().endsWith(".png")) {
42 resp.setContentType("image/png");
44 resp.getOutputStream().write(InputStreamToByteArray.convert(new FileInputStream(file)));
45 } else if (file.getAbsolutePath().endsWith(".psd")) {
46 PSDReader psdr = new PSDReader();
47 psdr.read(new FileInputStream(file));
48 Image img = psdr.getImage();
49 if (req.getParameter("height") != null) {
50 int height = Integer.parseInt(req.getParameter("height"));
51 int width = (img.getWidth(null) * height) / img.getHeight(null);
52 img = ((BufferedImage)img).getScaledInstance(width, height, Image.SCALE_SMOOTH);
54 System.out.println("bufferedimage is " + img);
55 if (!(img instanceof BufferedImage)) {
56 BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
57 bi.getGraphics().drawImage(img, 0, 0, null);
60 PngEncoderB pngenc = new PngEncoderB((BufferedImage)img, true);
61 resp.setContentType("image/png");
63 resp.getOutputStream().write(pngenc.pngEncode(true));
65 } catch(Exception exception) {
66 exception.printStackTrace();
67 throw new ServletException(exception);
71 private ServletContext cx;