mirror of https://github.com/halo-dev/halo
* 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
parent
35feddba18
commit
75c8bb22ee
|
@ -2,6 +2,7 @@ package run.halo.app.handler.file;
|
||||||
|
|
||||||
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.function.Supplier;
|
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 uploadResult updated result must not be null
|
||||||
* @param file multipart file must not be null
|
* @param file multipart file must not be null
|
||||||
* @param thumbnailSupplier thumbnail supplier
|
* @param thumbnailSupplier thumbnail supplier
|
||||||
|
@ -73,9 +76,19 @@ public interface FileHandler {
|
||||||
if (isImageType(file)) {
|
if (isImageType(file)) {
|
||||||
// Handle image
|
// Handle image
|
||||||
try (InputStream is = file.getInputStream()) {
|
try (InputStream is = file.getInputStream()) {
|
||||||
ImageReader image = ImageUtils.getImageReaderFromFile(is, uploadResult.getSuffix());
|
String extension = uploadResult.getSuffix();
|
||||||
uploadResult.setWidth(image.getWidth(0));
|
if (ImageUtils.EXTENSION_ICO.equals(extension)) {
|
||||||
uploadResult.setHeight(image.getHeight(0));
|
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) {
|
if (thumbnailSupplier != null) {
|
||||||
uploadResult.setThumbPath(thumbnailSupplier.get());
|
uploadResult.setThumbPath(thumbnailSupplier.get());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue