Thumbnails压缩图片大小后再上传
具体代码:MultipartFile uploadImage;String type = MIMEenum.get(uploadImage.getContentType());File img = File.createTempFile("jpg", type);uploadImage.transferTo(img);if (uploadImage.getSize() >= SIZE_PIO
·
具体代码:
MultipartFile uploadImage;
String type = MIMEenum.get(uploadImage.getContentType());
File img = File.createTempFile("jpg", type);
uploadImage.transferTo(img);
if (uploadImage.getSize() >= SIZE_PIONT_FIVE * SIZE_ONE_ZERO_TWO_FOUR * SIZE_ONE_ZERO_TWO_FOUR) {
//图片尺寸不变,压缩图片文件大小outputQuality实现,参数1为最高质量
Thumbnails.of(img.getPath()).scale(1f).outputQuality(0.25f).toFile(img.getPath());
}
相关jar坐标:
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
更多推荐
已为社区贡献2条内容
所有评论(0)