<%@page contentType="image/jpeg"%> <%@page import="com.sun.image.codec.jpeg.*"%> <%@page import="java.awt.Graphics"%> <%@page import="java.awt.Image"%> <%@page import="java.awt.Color"%> <%@page import="java.awt.image.BufferedImage"%> <%@page import="java.io.FileInputStream"%> <%@ include file="includes/systempaths.jsp"%> <% int newWidth = INT_THUMB_WIDTH; int newHeight = INT_THUMB_HEIGHT; String sourcePath = photoUpload + "/start.jpg"; if (request.getParameter("randomimage") != null && request.getParameter("randomimage").equals("true") && request.getParameter("collectionid") != null) { %><%@ include file="includes/dbinclude.jsp"%><% Statement stmt = myConn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM photos WHERE collectionid=" + request.getParameter("collectionid") + " ORDER BY RAND() LIMIT 0,1"); if (rs.next()) { sourcePath = photoUpload + "/image" + rs.getString("imageid") + ".jpg"; } myConn.close(); } else if (request.getParameter("imageid") != null) { sourcePath = photoUpload + "/" + request.getParameter("imageid"); } else if (request.getParameter("src") != null) { sourcePath = universityBase + "/" + request.getParameter("src"); } if (request.getParameter("newwidth") != null) { //int tempWidth = newWidth; newWidth = Integer.parseInt((String)request.getParameter("newwidth")); //newHeight = (int)(((double)newWidth / (double)tempWidth) * (double)newHeight); } if (request.getParameter("newheight") != null) { //int tempWidth = newWidth; newHeight = Integer.parseInt((String)request.getParameter("newheight")); //newHeight = (int)(((double)newWidth / (double)tempWidth) * (double)newHeight); } try { FileInputStream hank = new FileInputStream(sourcePath); BufferedImage bi = com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(hank).decodeAsBufferedImage(); hank.close(); double heightRatio = ((double)newHeight) / ((double)bi.getHeight()); double widthRatio = ((double)newWidth) / ((double)bi.getWidth()); double useRatio = Math.min(widthRatio, heightRatio); if ("true".equals(request.getParameter("forcewidth"))) useRatio = widthRatio; else if ("true".equals(request.getParameter("forceheight"))) useRatio = heightRatio; newHeight = (int)(bi.getHeight() * useRatio); newWidth = (int)(bi.getWidth() * useRatio); Image bi2 = bi.getScaledInstance(newWidth, newHeight, bi.SCALE_AREA_AVERAGING); bi = new BufferedImage(newWidth, newHeight, bi.getType()); bi.getGraphics().drawImage(bi2, 0, 0, newWidth, newHeight, null); com.sun.image.codec.jpeg.JPEGImageEncoder sam = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(response.getOutputStream()); sam.encode(bi); } catch (Exception e) { } %>