thumbnailator 一个好用的图像处理工具集
2013-11-12 23:07
260 查看
thumbnailator 是一个好用的图像处理工具集,可以用来处理缩略图,功能全面,使用简单,目前的版本是 0.4.6 。今天搜索了下开源中国,竟然没收录这个工具(保留原文,此作备注:此处弄错了,OSC中收录了此工具并介绍),特推荐下。有需要的可以从这里下载:http://code.google.com/p/thumbnailator/,maven下也可以使用。有了这么好用的工具,就不用我们再去造轮子了。
先摘几段网站原文API 测试,很简单,一看就懂。
解释其中几个:
size(160, 160) 图像的尺寸,宽,高
rotate(90)旋转90度
watermark()加水印,在其中可以指定水印的大小和水印图
scale()缩放比例,scale(1.0f)为不缩放
sourceRegion(int x,int ,y,int width,int height)在某位置切割图片
In this example, the image from original.jpg is resized, and then saved to thumbnail.jpg.
Alternatively, Thumbnailator will accept file names as a String. Using File objects to specify image files is not required:
Thumbnails.of("original.jpg").size(160, 160.toFile("thumbnail.jpg");
This form can be useful when writing quick prototype code, or when Thumbnailator is being used from scripting languages.
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.8f).toFile(new File("image-with-watermark.jpg"));
In this example, the image from original.jpg is resized, then rotated to clockwise by 90 degrees, then a watermark is placed at the bottom right-hand corner which is half transparent, then is saved to image-with-watermark.jpg with 80% compression quality settings.
OutputStream os = ...; Thumbnails.of("large-picture.jpg").size(200, 200).outputFormat("png").toOutputStream(os);
In this example, an image from the file large-picture.jpg is resized to a maximum dimension of 200 x 200 (maintaining the aspect ratio of the original image) and writes the that to the specified OutputStream as a PNG image.
BufferedImage originalImage = ImageIO.read(new File("original.png")); BufferedImage thumbnail = Thumbnails.of(originalImage).size(200, 200).asBufferedImage();
The above code takes an image in originalImage and creates a 200 pixel by 200 pixel thumbnail using and stores the result in thumbnail.
BufferedImage originalImage = ImageIO.read(new File("original.png")); BufferedImage thumbnail = Thumbnails.of(originalImage).scale(0.25f).asBufferedImage();
The above code takes the image in originalImage and creates a thumbnail that is 25% of the original image, and uses the default scaling technique in order to make the thumbnail which is stored in thumbnail.
BufferedImage originalImage = ImageIO.read(new File("original.jpg")); BufferedImage thumbnail = Thumbnails.of(originalImage) .size(200, 200).rotate(90).asBufferedImage();
The above code takes the original image and creates a thumbnail which is rotated clockwise by 90 degrees.
BufferedImage originalImage = ImageIO.read(new File("original.jpg")); BufferedImage watermarkImage = ImageIO.read(new File("watermark.png")); BufferedImage thumbnail = Thumbnails.of(originalImage).size(200, 200). watermark(Positions.BOTTOM_RIGHT, watermarkImage, 0.5f) .asBufferedImage();
As shown, a watermark can be added to an thumbnail by calling the watermark method.
先摘几段网站原文API 测试,很简单,一看就懂。
解释其中几个:
size(160, 160) 图像的尺寸,宽,高
rotate(90)旋转90度
watermark()加水印,在其中可以指定水印的大小和水印图
scale()缩放比例,scale(1.0f)为不缩放
sourceRegion(int x,int ,y,int width,int height)在某位置切割图片
Create a thumbnail from an image file
Thumbnails.of(new File("original.jpg")).size(160, 160).toFile(new File("thumbnail.jpg"));In this example, the image from original.jpg is resized, and then saved to thumbnail.jpg.
Alternatively, Thumbnailator will accept file names as a String. Using File objects to specify image files is not required:
Thumbnails.of("original.jpg").size(160, 160.toFile("thumbnail.jpg");
This form can be useful when writing quick prototype code, or when Thumbnailator is being used from scripting languages.
Create a thumbnail with rotation and a watermark
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.8f).toFile(new File("image-with-watermark.jpg"));In this example, the image from original.jpg is resized, then rotated to clockwise by 90 degrees, then a watermark is placed at the bottom right-hand corner which is half transparent, then is saved to image-with-watermark.jpg with 80% compression quality settings.
Create a thumbnail and write to an OutputStream
OutputStream os = ...; Thumbnails.of("large-picture.jpg").size(200, 200).outputFormat("png").toOutputStream(os);In this example, an image from the file large-picture.jpg is resized to a maximum dimension of 200 x 200 (maintaining the aspect ratio of the original image) and writes the that to the specified OutputStream as a PNG image.
Creating fixed-size thumbnails
BufferedImage originalImage = ImageIO.read(new File("original.png")); BufferedImage thumbnail = Thumbnails.of(originalImage).size(200, 200).asBufferedImage();The above code takes an image in originalImage and creates a 200 pixel by 200 pixel thumbnail using and stores the result in thumbnail.
Scaling an image by a given factor
BufferedImage originalImage = ImageIO.read(new File("original.png")); BufferedImage thumbnail = Thumbnails.of(originalImage).scale(0.25f).asBufferedImage();The above code takes the image in originalImage and creates a thumbnail that is 25% of the original image, and uses the default scaling technique in order to make the thumbnail which is stored in thumbnail.
Rotating an image when creating a thumbnail
BufferedImage originalImage = ImageIO.read(new File("original.jpg")); BufferedImage thumbnail = Thumbnails.of(originalImage) .size(200, 200).rotate(90).asBufferedImage();The above code takes the original image and creates a thumbnail which is rotated clockwise by 90 degrees.
Creating a thumbnail with a watermark
BufferedImage originalImage = ImageIO.read(new File("original.jpg")); BufferedImage watermarkImage = ImageIO.read(new File("watermark.png")); BufferedImage thumbnail = Thumbnails.of(originalImage).size(200, 200). watermark(Positions.BOTTOM_RIGHT, watermarkImage, 0.5f) .asBufferedImage();As shown, a watermark can be added to an thumbnail by calling the watermark method.
相关文章推荐
- Ribbon+Opencv 2.4--实现一个简单的Opencv图像处理小工具
- 一个简单的变换——图像的平滑处理
- Photoscape for Mac(图像特效处理及编辑工具)中文破解版 V2.7.1专业版
- IE版图像处理工具-不需下载的照片处理软件,图象处理工具
- 一个图像滤光处理程序
- 一个贯穿图像处理与数据挖掘的永恒问题
- TexturePacker图像处理工具
- 图像处理工具包ImagXpress使用教程:多页TIFF编辑API的使用(一)
- 在 NASA 使用开源工具进行图像处理
- 医学图像数据集和处理工具【总结】
- PIL python的一个图像处理库 支持 python3
- 用Canvas+Javascript FileAPI 实现一个跨平台的图片剪切、滤镜处理、上传下载工具(转)
- 一个openMP编程处理图像的示例
- 最近的在做一个Arc Engine图元叠加关系处理工具
- TexturePacker 非常棒的图像处理工具
- 一个经典实用的PHP图像处理类分享
- c#图像处理入门的一个好方法-bitmap类和图像像素值获取方法
- 数字图像处理中所用数学工具1---阵列与矩阵操作
- 医学图像处理工具包ITK