@Async
public String createThumbnail(UserFile userFile) {
String path = userFile.getPath();
Path originalImagePath = Paths.get(properties.getUploadFileRootPath(), path);
try {
BufferedImage originalImage = ImageIO.read(originalImagePath.toFile());
if (originalImage != null) {
BufferedImage thumbnailImage = this.createThumbnailImage(originalImage, 300, 200);
String ext = path.substring(path.lastIndexOf(".") + 1);
Path thumbNailPath = Paths.get(properties.getUploadFileRootPath(), userFile.getThumbnailPath());
ImageIO.write(thumbnailImage, ext, Files.newOutputStream(thumbNailPath));
return thumbNailPath.toString();
}
} catch (IOException e) {
logger.error("Failed to create thumbnail of '{}'", path);
}
return "";
}
UserFileService.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:osoon
作者:
评论列表
文章目录