爷的眼睛闪亮
insideDotNet En_summerGarden
 public static void uploadFile(MultipartFile multfile, String filePath) throws Exception {
File targetFile = new File(filePath);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
try {
//按比例压缩
Thumbnails.of(multfile.getInputStream()).scale(0.4f).outputQuality(0.25f).toFile(filePath);//filePath:上传图片的路径eg: xxx/xxx/xxx.jpg
//按尺寸压缩
//Thumbnails.of(multfile.getInputStream()).size(100,100).keepAspectRatio(false).toFile(filePath);
} catch (Exception e) {
log.info("压缩图片出现异常:", e);
}
}

<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
posted on 2018-08-02 17:27  爷的眼睛闪亮  阅读(191)  评论(0编辑  收藏  举报