From 2c63cad80e6aa15c8103ce256cf7bf344cc09663 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:03:21 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20png=E5=BD=A2=E5=BC=8F=E3=81=AE=E7=94=BB?= =?UTF-8?q?=E5=83=8F=E3=81=AE=E4=B8=80=E6=99=82=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E4=BD=9C=E6=88=90=E3=81=AB=E5=A4=B1=E6=95=97?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../image/ImageMediaProcessService.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessService.kt index d61d32ef..c713a63e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/converter/image/ImageMediaProcessService.kt @@ -13,6 +13,8 @@ import net.coobird.thumbnailator.Thumbnails import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Qualifier import org.springframework.stereotype.Service +import java.awt.Color +import java.awt.image.BufferedImage import java.nio.file.Files import java.nio.file.Path import java.util.* @@ -57,7 +59,14 @@ class ImageMediaProcessService(private val imageMediaProcessorConfiguration: Ima filePath: Path, thumbnails: Path? ): ProcessedMediaPath = withContext(Dispatchers.IO + MDCContext()) { - val bufferedImage = ImageIO.read(filePath.inputStream()) + val read = ImageIO.read(filePath.inputStream()) + + val bufferedImage = BufferedImage(read.width, read.height, BufferedImage.TYPE_INT_RGB) + + val graphics = bufferedImage.createGraphics() + + graphics.drawImage(read, 0, 0, Color.BLACK, null) + val tempFileName = UUID.randomUUID().toString() val tempFile = Files.createTempFile(tempFileName, "tmp") @@ -67,9 +76,15 @@ class ImageMediaProcessService(private val imageMediaProcessorConfiguration: Ima tempThumbnailFile.outputStream().use { val write = ImageIO.write( if (thumbnails != null) { - Thumbnails.of(thumbnails.toFile()).size(width, height).asBufferedImage() + Thumbnails.of(thumbnails.toFile()) + .size(width, height) + .imageType(BufferedImage.TYPE_INT_RGB) + .asBufferedImage() } else { - Thumbnails.of(bufferedImage).size(width, height).asBufferedImage() + Thumbnails.of(bufferedImage) + .size(width, height) + .imageType(BufferedImage.TYPE_INT_RGB) + .asBufferedImage() }, convertType, it