fix: 상품 이미지 업로드 투명도 보존

This commit is contained in:
이주일
2026-07-17 14:45:55 +09:00
parent 5e4d837012
commit 713bd6a64d

View File

@@ -310,8 +310,13 @@ public class FileStorageService {
if(image != null) { if(image != null) {
thumbnail = image.getScaledInstance(destWidth, destHeight, Image.SCALE_SMOOTH); thumbnail = image.getScaledInstance(destWidth, destHeight, Image.SCALE_SMOOTH);
} }
BufferedImage convertImage = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB); BufferedImage convertImage = new BufferedImage(destWidth, destHeight, getImageType(image, file.getOriginalFilename()));
convertImage.getGraphics().drawImage(thumbnail, posX, posY, null); Graphics graphics = convertImage.getGraphics();
try {
graphics.drawImage(thumbnail, posX, posY, null);
} finally {
graphics.dispose();
}
String ext = FilenameUtils.getExtension(file.getOriginalFilename()); String ext = FilenameUtils.getExtension(file.getOriginalFilename());
ImageIO.write(convertImage, ext, os); ImageIO.write(convertImage, ext, os);
@@ -376,8 +381,13 @@ public class FileStorageService {
if(image != null) { if(image != null) {
thumbnail = image.getScaledInstance(destWidth, destHeight, Image.SCALE_SMOOTH); thumbnail = image.getScaledInstance(destWidth, destHeight, Image.SCALE_SMOOTH);
} }
BufferedImage convertImage = new BufferedImage(thumbnailWidth, thumbnailHeight, BufferedImage.TYPE_INT_RGB); BufferedImage convertImage = new BufferedImage(thumbnailWidth, thumbnailHeight, getImageType(image, file.getOriginalFilename()));
convertImage.getGraphics().drawImage(thumbnail, posX, posY, null); Graphics graphics = convertImage.getGraphics();
try {
graphics.drawImage(thumbnail, posX, posY, null);
} finally {
graphics.dispose();
}
ImageIO.write(convertImage, ext, os); ImageIO.write(convertImage, ext, os);
}catch (WnbtRestException wre){ }catch (WnbtRestException wre){
@@ -407,6 +417,14 @@ public class FileStorageService {
return thumbnail_file; 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 에 지정된 경로에 저장이 됨 * combineFilePath 에 지정된 경로에 저장이 됨