썸네일 만들 이미지를 넣는 폼 테이블
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<%@ 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>
<center>
<h3>Thumbnail 이미지 폼 예제</h3>
<form action="Thumbnail.jsp" method="post" enctype="multipart/form-data">
이미지 파일 : <input type="file" name="filename">
<p>
<input type="submit" value="전송">
</form>
</center>
</body>
</html>
|
cs |
썸네일 만들고 출력하는 곳
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<%@page import="java.io.*"%>
<%@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.util.Enumeration"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@page import="java.awt.image.renderable.ParameterBlock"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
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);
%>
<!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>이미지 썸네일 예제</title>
</head>
<body>
- 원본 이미지 -<br>
<img src="Image/<%=filename %>"><p>
<img src="Image/sm_<%=filename %>">
</body>
</html>
|
cs |
'Programming > [JSP]' 카테고리의 다른 글
[JSTL] for tokens를 forEach로 바꾸기 (0) | 2018.05.05 |
---|---|
[JSP] 톰캣으로 프로젝트 실행시 시작페이지 설정 (0) | 2018.05.03 |
[JSP] 파일 업로드 기초 (0) | 2018.05.01 |
[JSP] template (0) | 2018.04.16 |
[JSP][JAVA BEANS] 회원가입 유효성 검사 (2) | 2018.04.16 |