[Spring][쇼핑몰 프로젝트][24] 상품 이미지 업로드(썸네일 생성 및 저장-2) - 5
https://kimvampa.tistory.com/219
This commit is contained in:
@@ -231,6 +231,14 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<!-- thumbnail -->
|
||||
<!-- https://mvnrepository.com/artifact/net.coobird/thumbnailator -->
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.13</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -231,6 +231,14 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<!-- thumbnail -->
|
||||
<!-- https://mvnrepository.com/artifact/net.coobird/thumbnailator -->
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.13</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
|
||||
@@ -230,6 +230,13 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<!-- thumbnail -->
|
||||
<!-- https://mvnrepository.com/artifact/net.coobird/thumbnailator -->
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.13</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -230,6 +230,13 @@
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<!-- thumbnail -->
|
||||
<!-- https://mvnrepository.com/artifact/net.coobird/thumbnailator -->
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.13</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user