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 <Jenson.zq@gmail.com>
pull/1479/head
Qiang156 2021-09-13 10:15:27 +02:00 committed by GitHub
parent 35feddba18
commit 75c8bb22ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -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());
}