使用Java将图片转化为高清缩略图
简述:
遇到一个业务需求,需要将上传的图片生成一份高清缩略图,查询了了很多方法,效果都不理想。最终找到thumbnailator.jar,轻松解决。
代码:
//oldFilePath(原始图片地址)
//newFilePath(生成的缩略图地址)
Thumbnails.of(new File(oldFilePath))
.size(100,100)
.toFile(new File(newFilePath));
或者
Thumbnails.of(oldFilePath)
.size(100,100)
.toFile(newFilePath);
依赖:
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
结语:
仅用于帮助那些需要的人,更为细致的用法请自行探索。