Thumbnails.of(new File("path/to/directory").listFiles())
.size(640, 480)
.outputFormat("jpg")
.toFiles(Rename.PREFIX_DOT_THUMBNAIL);
// 可变长度参数列表
public static Builder<File> of(String... files) {...}
public static Builder<File> of(File... files) {...}
public static Builder<URL> of(URL... urls) {...}
public static Builder<? extends InputStream> of(InputStream... inputStreams) {...}
public static Builder<BufferedImage> of(BufferedImage... images) {...}
// 迭代器(所有实现 Iterable 接口的 Java 对象都可以,当然也包括 List、Set)
public static Builder<File> fromFilenames(Iterable<String> files) {...}
public static Builder<File> fromFiles(Iterable<File> files) {...}
public static Builder<URL> fromURLs(Iterable<URL> urls) {...}
public static Builder<InputStream> fromInputStreams(Iterable<? extends InputStream> inputStreams) {...}
public static Builder<BufferedImage> fromImages(Iterable<BufferedImage> images) {...}
public Builder<T> size(int width, int height)
{
updateStatus(Properties.SIZE, Status.ALREADY_SET);
updateStatus(Properties.SCALE, Status.CANNOT_SET);
validateDimensions(width, height);
this.width = width;
this.height = height;
return this;
}
Thumbnails.of(new File("original.jpg"))
.size(160, 160)
.rotate(90)
.watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File("watermark.png")), 0.5f)
.outputQuality(0.8)
.toFile(new File("image-with-watermark.jpg"));
// 返回图片缓存
public List<BufferedImage> asBufferedImages() throws IOException {...}
public BufferedImage asBufferedImage() throws IOException {...}
// 返回文件列表
public List<File> asFiles(Iterable<File> iterable) throws IOException {...}
public List<File> asFiles(Rename rename) throws IOException {...}
public List<File> asFiles(File destinationDir, Rename rename) throws IOException {...}
// 创建文件
public void toFile(File outFile) throws IOException {...}
public void toFile(String outFilepath) throws IOException {...}
public void toFiles(Iterable<File> iterable) throws IOException {...}
public void toFiles(Rename rename) throws IOException {...}
public void toFiles(File destinationDir, Rename rename) throws IOException {...}
// 创建输出流
public void toOutputStream(OutputStream os) throws IOException {...}
public void toOutputStreams(Iterable<? extends OutputStream> iterable) throws IOException {...}
<dependency> <groupId>net.coobird</groupId> <artifactId>thumbnailator</artifactId> <version>[0.4, 0.5)</version> </dependency>
Thumbnails.of("oldFile.png")
.size(16, 16)
.toFile("newFile_16_16.png");
Thumbnails.of("oldFile.png")
.scale(2.0)
.toFile("newFile_scale_2.0.png");
Thumbnails.of("oldFile.png")
.scale(1.0, 0.5)
.toFile("newFile_scale_1.0_0.5.png");
Thumbnails.of("oldFile.png")
.scale(0.8)
.rotate(90)
.toFile("newFile_rotate_90.png");
Thumbnails.of("oldFile.png")
.scale(0.8)
.rotate(180)
.toFile("newFile_rotate_180.png");
BufferedImage watermarkImage = ImageIO.read(new File("wartermarkFile.png"));
Thumbnails.of("oldFile.png")
.scale(0.8)
.watermark(Positions.BOTTOM_LEFT, watermarkImage, 0.5f)
.toFile("newFile_watermark.png");
BufferedImage watermarkImage = ImageIO.read(new File("wartermarkFile.png"));
File destinationDir = new File("D:\watermark\");
Thumbnails.of("oldFile.png", "oldFile2.png")
.scale(0.8)
.watermark(Positions.BOTTOM_LEFT, watermarkImage, 0.5f)
.toFiles(destinationDir, Rename.PREFIX_DOT_THUMBNAIL);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有