From 75c8bb22eeb452f8a668cfffaff0eb937682ac25 Mon Sep 17 00:00:00 2001 From: Qiang156 <90432997+Qiang156@users.noreply.github.com> Date: Mon, 13 Sep 2021 10:15:27 +0200 Subject: [PATCH] fix: the problem of without dimension information when uploading an ICO picture #1473 (#1474) * fixed #1473 * fixed the problem of without dimension information when uploading an ICO picture#1473 Co-authored-by: Jenson-Mac --- .../halo/app/handler/file/FileHandler.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/run/halo/app/handler/file/FileHandler.java b/src/main/java/run/halo/app/handler/file/FileHandler.java index 3b01ff227..dc4805b9d 100644 --- a/src/main/java/run/halo/app/handler/file/FileHandler.java +++ b/src/main/java/run/halo/app/handler/file/FileHandler.java @@ -2,6 +2,7 @@ package run.halo.app.handler.file; import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR; +import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.util.function.Supplier; @@ -63,6 +64,8 @@ public interface FileHandler { } /** + * Update Metadata for image object. + * * @param uploadResult updated result must not be null * @param file multipart file must not be null * @param thumbnailSupplier thumbnail supplier @@ -73,9 +76,19 @@ public interface FileHandler { if (isImageType(file)) { // Handle image try (InputStream is = file.getInputStream()) { - ImageReader image = ImageUtils.getImageReaderFromFile(is, uploadResult.getSuffix()); - uploadResult.setWidth(image.getWidth(0)); - uploadResult.setHeight(image.getHeight(0)); + String extension = uploadResult.getSuffix(); + if (ImageUtils.EXTENSION_ICO.equals(extension)) { + BufferedImage icoImage = + ImageUtils.getImageFromFile(is, extension); + uploadResult.setWidth(icoImage.getWidth()); + uploadResult.setHeight(icoImage.getHeight()); + } else { + ImageReader image = + ImageUtils.getImageReaderFromFile(is, extension); + uploadResult.setWidth(image.getWidth(0)); + uploadResult.setHeight(image.getHeight(0)); + } + if (thumbnailSupplier != null) { uploadResult.setThumbPath(thumbnailSupplier.get()); }