2019独角兽企业重金招聘Python工程师标准>>>

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)在某位置切割图片

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.

转载于:https://my.oschina.net/guhai2004/blog/175801

thumbnailator 一个好用的图像处理工具集相关推荐

  1. Vulcanexus机器人操作系统ROS2一站式工具集(Galactic+Humble)

    什么是Vulcanexus? Vulcanexus 是用于开发机器人应用程序的开源软件堆栈. 它提供了各种库和工具,用于轻松和个性化地配置机器人项目. Vulcanexus 是一个一体化的 ROS 2 ...

  2. Wifitap是一个WiFi注入工具集常用命令集合大学霸IT达人

    Wifitap是一个WiFi注入工具集常用命令集合大学霸IT达人 该工具集允许任何应用程序都可以发送和接收IP数据包,使用802.11流量捕获和注入,并通过WiFi网络简单配置接口wj0.Wifita ...

  3. Tailwind CSS 是一个工具集 CSS 框架

    Tailwind CSS 是一个工具集 CSS 框架, 助你快速实现定制化的网站设计. Tailwind CSS 是一个高度可定制的基础层 CSS 框架,它为您提供了构建定制化设计所需的所有构建块,而 ...

  4. (三)线程同步工具集_1---控制线程并发访问一个资源

    2019独角兽企业重金招聘Python工程师标准>>> 线程同步工具集 在前面了解了线程的同步机制,临界区等,了解了线程的两种基本的同步机制: synchronized关键字: Lo ...

  5. 2018.06.25 一个不知道叫什么好的U盘启动工具集

    先说版权 这个PE工具集已经被一些商人盯上了! 先说明一下.这个PE工具集不允许拿来做任何商业活动,但是个人是免费下载和使用和研究的! 有些商家用这个赚钱不说还不愿意放出官方的帖子链接,用意何在?用我 ...

  6. Golang:imaging一个简单、实用的图像处理工具

    Imaging is a simple image processing package for Go 译文:Imaging是一个简单图像处理的Go语言包 文档: https://github.com ...

  7. caTools一个奇特的工具集

    R的极客理想系列文章,涵盖了R的思想,使用,工具,创新等的一系列要点,以我个人的学习和体验去诠释R的强大. R语言作为统计学一门语言,一直在小众领域闪耀着光芒.直到大数据的爆发,R语言变成了一门炙手可 ...

  8. 推荐一个3D建模工具集

    3D建模工具集, 收录一下几个工具集: 数字孪生编辑器         基于WebGL技术,依托丰富的模型资产库,通过拖拽式的操作,方便用户高效便捷的搭建三维数字孪生场景,配合twin服务平台,实现孪 ...

  9. [转]《吐血整理》系列-顶级程序员工具集

    你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图.个人联系方式,欢迎Star和指教 前言 这期 ...

最新文章

  1. Lucene核心数据结构——FST存词典,跳表存倒排或者roarning bitmap 见另外一个文章...
  2. android组合动画还原,Android - Fragment,View动画,组合动画,属性动画
  3. xx = [example[x] for example in xxx]功能解析
  4. 水晶报表使用经验谈1--建立水晶报表第一步及编译最易出现错误的解决方法及报表转换成pdf文档进行打印方法...
  5. mipi和isp处理_图像信号处理 (ISP) 流水线
  6. 北京一Model 3失控冲向公交站台,特斯拉调查后回应......
  7. 瑞幸咖啡恢复交易 股价大跌35.76%
  8. HDOJ 1420 Prepared for New Acmer(DP)
  9. 知识图谱最新研究综述
  10. 设计模式:(生成器模式)
  11. echart 地图 某个地区_一个让echarts中国地图包含省市轮廓的技巧
  12. ORA-01033问题:定位redo日志进行不完全恢复启库实战案例
  13. markdown 转 pdf
  14. 如何配置CK-S610-A01半导体读写器的RFID工具擦写TI低频玻璃管标签RI-TRP-DR2B-40的UID号
  15. Python爬虫大众点评字体加密评论采集!听说这个网站很难?
  16. kubernetes云原生纪元:共享存储-PVPVC(上)
  17. [编程题]走斜线Java
  18. 【容易打工网】大学生职场励志箴言励志语录
  19. android 与地图互动,高德、百度和腾讯三家比拼,哪个 Android 车机地图 App 更好用?...
  20. 让你彩虹QQ显示你的IP一天72变

热门文章

  1. vue js 和原生app调用回调方法问题
  2. 小甲鱼Python第二十二讲课后习题
  3. springMVC 配置和使用
  4. PowerEdge服务器生命周期控制器:Lifecycle Controller
  5. 记:Ubuntu 14.04 安装32位库支持库失败
  6. 【读书笔记】并发编程需要注意的几个典型问题
  7. web developer tips (55):多项目解决方案中设置启动项
  8. 中央民族大学计算机考研考什么,中央民族大学电子信息专业硕士研究生入学考试初试科目考试大纲...
  9. python图片转字符_二十行python代码实现图片转字符
  10. 我面试几乎必问:你设计索引的原则是什么?怎么避免索引失效?