<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.Graphics2D"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="javax.media.jai.JAI"%>
<%@page import="javax.media.jai.RenderedOp"%>
<%@page import="java.awt.image.renderable.ParameterBlock"%>
<%@page import="java.util.Enumeration"%>
<%@page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page import="java.io.*"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
String imagePath = request.getRealPath("image");
int size = 1 * 1024 * 1024;
String filename = "";
try {
MultipartRequest multi = new MultipartRequest(request, imagePath, size, "euc-kr",
new DefaultFileRenamePolicy());
Enumeration files = multi.getFileNames();
String file = (String) files.nextElement();
filename = multi.getFilesystemName(file);
} catch (Exception e) {
e.printStackTrace();
}
ParameterBlock pb = new ParameterBlock();
pb.add(imagePath + "/" + filename);
RenderedOp rOp = JAI.create("fileload", pb);
BufferedImage bi = rOp.getAsBufferedImage();
BufferedImage thumb = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
Graphics2D g = thumb.createGraphics();
g.drawImage(bi, 0, 0, 100, 100, null);
File file = new File(imagePath + "/sm_" + filename);
ImageIO.write(thumb, "jpg", file);
%>
-원본 이미지-
<br>
<img src="image/<%=filename%>">
<p>
-썸네일 이미지-<br> <img src="image/sm_<%=filename%>">
</body>
</html>
'JAVA > JSP' 카테고리의 다른 글
JsTl 체크박스 체크 조건문 (0) | 2016.09.08 |
---|---|
jsp 차단된 콘텐츠 허용 코드 (0) | 2016.08.29 |
JSP jai 라이브러리 다운 및 추가 (0) | 2015.08.25 |
JSP Thumbnail 폼 (0) | 2015.08.25 |
JSP 파일업로드 (업로드되는 디렉터리 & cos.jar 추가 및 다운로드) (0) | 2015.08.25 |