fix: 상품 이미지 업로드 투명도 보존
This commit is contained in:
@@ -310,8 +310,13 @@ public class FileStorageService {
|
||||
if(image != null) {
|
||||
thumbnail = image.getScaledInstance(destWidth, destHeight, Image.SCALE_SMOOTH);
|
||||
}
|
||||
BufferedImage convertImage = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB);
|
||||
convertImage.getGraphics().drawImage(thumbnail, posX, posY, null);
|
||||
BufferedImage convertImage = new BufferedImage(destWidth, destHeight, getImageType(image, file.getOriginalFilename()));
|
||||
Graphics graphics = convertImage.getGraphics();
|
||||
try {
|
||||
graphics.drawImage(thumbnail, posX, posY, null);
|
||||
} finally {
|
||||
graphics.dispose();
|
||||
}
|
||||
|
||||
String ext = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
ImageIO.write(convertImage, ext, os);
|
||||
@@ -376,8 +381,13 @@ public class FileStorageService {
|
||||
if(image != null) {
|
||||
thumbnail = image.getScaledInstance(destWidth, destHeight, Image.SCALE_SMOOTH);
|
||||
}
|
||||
BufferedImage convertImage = new BufferedImage(thumbnailWidth, thumbnailHeight, BufferedImage.TYPE_INT_RGB);
|
||||
convertImage.getGraphics().drawImage(thumbnail, posX, posY, null);
|
||||
BufferedImage convertImage = new BufferedImage(thumbnailWidth, thumbnailHeight, getImageType(image, file.getOriginalFilename()));
|
||||
Graphics graphics = convertImage.getGraphics();
|
||||
try {
|
||||
graphics.drawImage(thumbnail, posX, posY, null);
|
||||
} finally {
|
||||
graphics.dispose();
|
||||
}
|
||||
|
||||
ImageIO.write(convertImage, ext, os);
|
||||
}catch (WnbtRestException wre){
|
||||
@@ -407,6 +417,14 @@ public class FileStorageService {
|
||||
return thumbnail_file;
|
||||
}
|
||||
|
||||
private int getImageType(BufferedImage image, String originalFileName) {
|
||||
String ext = FilenameUtils.getExtension(originalFileName).toLowerCase(Locale.ROOT);
|
||||
boolean supportsAlpha = "png".equals(ext) || "gif".equals(ext);
|
||||
return image != null && image.getColorModel().hasAlpha() && supportsAlpha
|
||||
? BufferedImage.TYPE_INT_ARGB
|
||||
: BufferedImage.TYPE_INT_RGB;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* combineFilePath 에 지정된 경로에 저장이 됨
|
||||
@@ -715,4 +733,4 @@ public class FileStorageService {
|
||||
return rtnStr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user