UserFileService.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:osoon 作者:
@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 "";
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号