[Spring][쇼핑몰 프로젝트][24] 상품 이미지 업로드(썸네일 생성 및 저장) - 5
https://kimvampa.tistory.com/218
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.vam.controller;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -7,6 +9,8 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -306,9 +310,25 @@ public class AdminController {
|
||||
|
||||
/* 파일 저장 */
|
||||
try {
|
||||
|
||||
multipartFile.transferTo(saveFile);
|
||||
|
||||
/* 썸네일 생성(ImageIO) */
|
||||
File thumbnailFile = new File(uploadPath, "s_" + uploadFileName);
|
||||
|
||||
BufferedImage bo_image = ImageIO.read(saveFile);
|
||||
BufferedImage bt_image = new BufferedImage(300, 500, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
Graphics2D graphic = bt_image.createGraphics();
|
||||
|
||||
graphic.drawImage(bo_image, 0, 0,300,500, null);
|
||||
|
||||
ImageIO.write(bt_image, "jpg", thumbnailFile);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Mon May 10 18:17:39 KST 2021
|
||||
#Thu May 13 02:59:13 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
|
||||
m2e.projectName=VamPa
|
||||
groupId=com.vam
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.vam.controller;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -307,9 +311,25 @@ public class AdminController {
|
||||
|
||||
/* 파일 저장 */
|
||||
try {
|
||||
|
||||
multipartFile.transferTo(saveFile);
|
||||
|
||||
/* 썸네일 생성(ImageIO) */
|
||||
File thumbnailFile = new File(uploadPath, "s_" + uploadFileName);
|
||||
|
||||
BufferedImage bo_image = ImageIO.read(saveFile);
|
||||
BufferedImage bt_image = new BufferedImage(300, 500, BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
Graphics2D graphic = bt_image.createGraphics();
|
||||
|
||||
graphic.drawImage(bo_image, 0, 0,300,500, null);
|
||||
|
||||
ImageIO.write(bt_image, "jpg", thumbnailFile);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Mon May 10 18:17:39 KST 2021
|
||||
#Thu May 13 02:59:11 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL
|
||||
m2e.projectName=VamPa_MySQL
|
||||
groupId=com.vam
|
||||
|
||||
Reference in New Issue
Block a user