最佳图像缩放库
我搜索并找到了一些 Java 图像缩放库。但不确定该选哪一个。我需要从服务器上传的图像生成缩略图。
如果你能分辨出哪个好哪个坏,那就太好了。
我的列表是:
- JMagick
- im4java
- Thumbnailator
- java-image-scaling
- JAI
I have searched and found a few image scaling libraries for Java. But not sure which one to go with. I need to generate thumbnails from the image uploaded by server.
It would be great if you can tell which one's good and bad.
The list I have is:
- JMagick
- im4java
- Thumbnailator
- java-image-scaling
- JAI
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于我的简单需求,Thumbnailator 非常完美。小库;流畅、干净、文档齐全的 API。
就我而言,它只是
"net.coobird" % "thumbnailator" % "0.4.8"
依赖项和:并且完成。基本上它是 Java 2D API 之上的一个友好的包装器。对于特定(缩略图)需求有用;没有学习曲线。
除非您确实需要对图像进行一些繁重的工作,否则我会对依赖外部二进制文件(ImageMagick 和 JMagick 之类的包装器)保持警惕,这会增加复杂性并将部件移动到设置中。特别是如果您的堆栈与我的堆栈类似:在 Heroku 上运行的 Scala/Java 应用程序。是的,有像
heroku-buildpack-imagemagick-cedar-14
这样的东西,但是与应用程序捆绑在一起的简单依赖项更加干净。For my simple needs, Thumbnailator was perfect. Small lib; fluent, clean, well-documented API.
In my case, it was just
"net.coobird" % "thumbnailator" % "0.4.8"
dependency and:and done. Basically it’s a friendly wrapper on top of the Java 2D APIs. Useful for specific (thumbnailin') needs; no learning curve.
Unless you really need to do some heavy-lifting with images, I'd be wary of depending on an external binary (ImageMagick and wrappers like JMagick), which would add complexity and moving parts into the setup. Especially if your stack is something like mine: Scala/Java app running on Heroku. There’s stuff like
heroku-buildpack-imagemagick-cedar-14
, yes, but a simple dependency bundled with the app is infinitely cleaner.如果您需要高质量的缩略图,用于生成缩略图的 Java API 还不够好。
要生成高质量的缩略图,请使用您列出的框架。我尝试过 ImgScalr (https://github.com/thebuzzmedia/imgscalr) 和缩略图。
通过我的微基准测试(不能真正用于通用结论),缩略图器更快 - 尽管不是很多,而且更容易 - 特别是在生成具有透明度的缩略图时。
我也尝试了 JMagick,但在编译代码和设置时遇到了问题。还有点担心以后会遇到问题,因为框架的基本代码是用我根本不理解的语言 - C 编写的。
您可能还会发现这里的讨论很有用:如何使用 Java 调整图像大小?
Java API to generate thumbnails is not good enough if you need high quality thumbnails.
To generate high quality thumbnails use a framework like the ones you have listed. I have tried ImgScalr (https://github.com/thebuzzmedia/imgscalr) and Thumbnailator.
With my microbenchmark tests (cannot really be used for general purpose conclusions) Thumbnailator is faster - though not by a lot, and easier - especially when generating thumbnails with transparency.
I also trying out JMagick but running into issues just compiling the code and setting it up. Also a little worried about running into issues later with a framework whose basic code is written in a language I don't understand at all - C.
You might also find useful the discussion here: How can I resize an image using Java?
在我的私人项目中,我不使用任何特定的库,为 Java 提供的功能为我提供了不错的结果。如果你只想做图像缩放,那么一个完整的图像处理库就太重量级了。
我使用 http://www 中给出的代码片段.mkyong.com/java/how-to-resize-an-image-in-java/ 效果很好。
In my private projects, I don't use any specific library, the functionality provided for Java gives decent results for me. If you just want to do image scaling, then a complete image processing library would be too heavyweighted.
I use the code snippets given in http://www.mkyong.com/java/how-to-resize-an-image-in-java/ which works quite well.