Thumbnails压缩图片大小后再上传

2022-11-28 16:29:13 浏览数 (1)

具体代码:

代码语言:javascript复制
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坐标:

代码语言:javascript复制
        <dependency>
            <groupId>net.coobird</groupId>
            <artifactId>thumbnailator</artifactId>
            <version>0.4.8</version>
        </dependency>
jar

0 人点赞