fix error when input ico

pull/353/head
weiwensangsang 2019-10-31 00:48:31 +08:00
parent c640afc3a0
commit b769843282
2 changed files with 18 additions and 3 deletions

View File

@ -56,6 +56,7 @@ ext {
jgitVersion = '5.3.0.201903130848-r'
flexmarkVersion = '0.42.12'
thumbnailatorVersion = '0.4.8'
image4jVersion = '0.7zensight1'
}
dependencies {
@ -96,7 +97,8 @@ dependencies {
implementation "com.vladsch.flexmark:flexmark-html-parser:$flexmarkVersion"
implementation "net.coobird:thumbnailator:$thumbnailatorVersion"
implementation "net.sf.image4j:image4j:$image4jVersion"
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'
@ -106,4 +108,4 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}
}

View File

@ -17,13 +17,16 @@ import run.halo.app.utils.HaloUtils;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;
import net.sf.image4j.codec.ico.ICODecoder;
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
@ -151,7 +154,7 @@ public class LocalFileHandler implements FileHandler {
Path thumbnailPath = Paths.get(workDir + thumbnailSubFilePath);
// Read as image
BufferedImage originalImage = ImageIO.read(uploadPath.toFile());
BufferedImage originalImage = getImageFromFile(uploadPath.toFile(), extension);
// Set width and height
uploadResult.setWidth(originalImage.getWidth());
uploadResult.setHeight(originalImage.getHeight());
@ -239,4 +242,14 @@ public class LocalFileHandler implements FileHandler {
return result;
}
private BufferedImage getImageFromFile(File file, String extension) throws IOException {
log.debug("Current File type is : [{}]", extension);
if ("ico".equals(extension)) {
return ICODecoder.read(file).get(0);
} else {
return ImageIO.read(file);
}
}
}