java实现图片压缩

依赖:

<dependency>
    <groupId>net.coobird</groupId>
    <artifactId>thumbnailator</artifactId>
    <version>0.4.7</version>
</dependency>

代码:

        
//realPath是保存到的目标地址
String realPath = "/home/img/test.jpeg";
//file是接口收到的文件
Thumbnails.of(file.getInputStream()).size(500, 800).toFile(realPath);

参考:文章1  文章2

原文地址:https://www.cnblogs.com/xuchao0506/p/15529915.html