Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed the problem of without dimension information when uploading an ICO picture #1473 #1474

Merged
merged 2 commits into from
Sep 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/main/java/run/halo/app/handler/file/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -63,6 +64,8 @@ default boolean isImageType(@NonNull MultipartFile file) {
}

/**
* 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
Expand All @@ -73,9 +76,19 @@ default void handleImageMetadata(@NonNull MultipartFile file,
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());
}
Expand Down