日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

thumbnailator 一个好用的图像处理工具集

發(fā)布時間:2025/3/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 thumbnailator 一个好用的图像处理工具集 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

thumbnailator 是一個好用的圖像處理工具集,可以用來處理縮略圖,功能全面,使用簡單,目前的版本是?0.4.6 。今天搜索了下開源中國,竟然沒收錄這個工具(保留原文,此作備注:此處弄錯了,OSC中收錄了此工具并介紹),特推薦下。有需要的可以從這里下載:http://code.google.com/p/thumbnailator/,maven下也可以使用。有了這么好用的工具,就不用我們再去造輪子了。

先摘幾段網(wǎng)站原文API 測試,很簡單,一看就懂。

解釋其中幾個:

size(160, 160) ?圖像的尺寸,寬,高

rotate(90)旋轉(zhuǎn)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.


轉(zhuǎn)載于:https://my.oschina.net/guhai2004/blog/175801

總結(jié)

以上是生活随笔為你收集整理的thumbnailator 一个好用的图像处理工具集的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。