From 79e8a490efe77310c9fdbcc0968276d13c83220e Mon Sep 17 00:00:00 2001 From: SeoJin Kim Date: Thu, 13 May 2021 23:17:31 +0900 Subject: [PATCH] =?UTF-8?q?[Spring][=EC=87=BC=ED=95=91=EB=AA=B0=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8][24]=20=EC=83=81=ED=92=88?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C(?= =?UTF-8?q?=EC=8D=B8=EB=84=A4=EC=9D=BC=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5-2)=20-=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://kimvampa.tistory.com/219 --- VamPa/pom.xml | 8 ++++ .../com/vam/controller/AdminController.java | 36 ++++++++++++++--- .../maven/com.vam/controller/pom.properties | 2 +- .../META-INF/maven/com.vam/controller/pom.xml | 8 ++++ VamPa_MySQL/pom.xml | 7 ++++ .../com/vam/controller/AdminController.java | 40 ++++++++++++++++--- .../maven/com.vam/controller/pom.properties | 2 +- .../META-INF/maven/com.vam/controller/pom.xml | 7 ++++ 8 files changed, 97 insertions(+), 13 deletions(-) diff --git a/VamPa/pom.xml b/VamPa/pom.xml index 85d827a..6f9cd27 100644 --- a/VamPa/pom.xml +++ b/VamPa/pom.xml @@ -231,6 +231,14 @@ jackson-databind 2.12.1 + + + + net.coobird + thumbnailator + 0.4.13 + + diff --git a/VamPa/src/main/java/com/vam/controller/AdminController.java b/VamPa/src/main/java/com/vam/controller/AdminController.java index ed35268..4f110bb 100644 --- a/VamPa/src/main/java/com/vam/controller/AdminController.java +++ b/VamPa/src/main/java/com/vam/controller/AdminController.java @@ -1,9 +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; import java.util.Date; import java.util.List; @@ -32,6 +30,8 @@ import com.vam.model.PageDTO; import com.vam.service.AdminService; import com.vam.service.AuthorService; +import net.coobird.thumbnailator.Thumbnails; + @Controller @RequestMapping("/admin") public class AdminController { @@ -314,16 +314,42 @@ public class AdminController { multipartFile.transferTo(saveFile); /* 썸네일 생성(ImageIO) */ - File thumbnailFile = new File(uploadPath, "s_" + uploadFileName); + /* + File thumbnailFile = new File(uploadPath, "s_" + uploadFileName); BufferedImage bo_image = ImageIO.read(saveFile); - BufferedImage bt_image = new BufferedImage(300, 500, BufferedImage.TYPE_3BYTE_BGR); + + //비율 + double ratio = 3; + //넓이 높이 + int width = (int) (bo_image.getWidth() / ratio); + int height = (int) (bo_image.getHeight() / ratio); + + BufferedImage bt_image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphic = bt_image.createGraphics(); - graphic.drawImage(bo_image, 0, 0,300,500, null); + graphic.drawImage(bo_image, 0, 0,width,height, null); ImageIO.write(bt_image, "jpg", thumbnailFile); + */ + + /* 방법 2 */ + File thumbnailFile = new File(uploadPath, "s_" + uploadFileName); + + BufferedImage bo_image = ImageIO.read(saveFile); + + //비율 + double ratio = 3; + //넓이 높이 + int width = (int) (bo_image.getWidth() / ratio); + int height = (int) (bo_image.getHeight() / ratio); + + + Thumbnails.of(saveFile) + .size(width, height) + .toFile(thumbnailFile); + } catch (Exception e) { diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index 90c1884..9116bcd 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Thu May 13 02:59:13 KST 2021 +#Thu May 13 22:57:49 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa m2e.projectName=VamPa groupId=com.vam diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml index 85d827a..6f9cd27 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml @@ -231,6 +231,14 @@ jackson-databind 2.12.1 + + + + net.coobird + thumbnailator + 0.4.13 + + diff --git a/VamPa_MySQL/pom.xml b/VamPa_MySQL/pom.xml index 8776c16..595ac75 100644 --- a/VamPa_MySQL/pom.xml +++ b/VamPa_MySQL/pom.xml @@ -230,6 +230,13 @@ com.fasterxml.jackson.core jackson-databind 2.12.1 + + + + + net.coobird + thumbnailator + 0.4.13 diff --git a/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java b/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java index 098af60..2fbd2e1 100644 --- a/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java +++ b/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java @@ -31,6 +31,8 @@ import com.vam.model.PageDTO; import com.vam.service.AdminService; import com.vam.service.AuthorService; +import net.coobird.thumbnailator.Thumbnails; + @Controller @RequestMapping("/admin") public class AdminController { @@ -311,20 +313,46 @@ public class AdminController { /* 파일 저장 */ try { - + multipartFile.transferTo(saveFile); - + /* 썸네일 생성(ImageIO) */ - File thumbnailFile = new File(uploadPath, "s_" + uploadFileName); + /* + File thumbnailFile = new File(uploadPath, "s_" + uploadFileName); BufferedImage bo_image = ImageIO.read(saveFile); - BufferedImage bt_image = new BufferedImage(300, 500, BufferedImage.TYPE_3BYTE_BGR); + + //비율 + double ratio = 3; + //넓이 높이 + int width = (int) (bo_image.getWidth() / ratio); + int height = (int) (bo_image.getHeight() / ratio); + + BufferedImage bt_image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphic = bt_image.createGraphics(); - graphic.drawImage(bo_image, 0, 0,300,500, null); + graphic.drawImage(bo_image, 0, 0,width,height, null); + + ImageIO.write(bt_image, "jpg", thumbnailFile); + */ + + /* 방법 2 */ + File thumbnailFile = new File(uploadPath, "s_" + uploadFileName); + + BufferedImage bo_image = ImageIO.read(saveFile); + + //비율 + double ratio = 3; + //넓이 높이 + int width = (int) (bo_image.getWidth() / ratio); + int height = (int) (bo_image.getHeight() / ratio); + + + Thumbnails.of(saveFile) + .size(width, height) + .toFile(thumbnailFile); - ImageIO.write(bt_image, "jpg", thumbnailFile); } catch (Exception e) { diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index 49340e6..5b02b3a 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Thu May 13 02:59:11 KST 2021 +#Thu May 13 23:16:50 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL m2e.projectName=VamPa_MySQL groupId=com.vam diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml index 8776c16..595ac75 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml @@ -230,6 +230,13 @@ com.fasterxml.jackson.core jackson-databind 2.12.1 + + + + + net.coobird + thumbnailator + 0.4.13