优化图像 - 用Java无损压缩图像 [英] Optimize images - Losslessly compress images in Java

查看:2019
本文介绍了优化图像 - 用Java无损压缩图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拥有一个电子商务网站,我们拥有数以千计的产品图片。在google上检查pagespeed时它会显示如下:





我想知道,如果Java中有任何内置功能或任何第三方库可用,我们可以无损压缩所有我们托管的图片。因此,我们可以节省几个KB的客户。



通过互联网搜索我发现很少像punnypng和kraken付费,因此我们没有每月上传大量图片订阅它们是不值得的。我更喜欢Java或任何开源第三方库中的任何内置功能。<​​/ p>

我遇到 JAI ,但不确定是否解决这个问题与否。有实际操作经验的人吗?



P.S。我们正在使用Java 8

解决方案

你看过javax.imageio包中的类( http://docs.oracle.com/javase/7/docs/api/javax /imageio/package-summary.html )?



您可以对图像进行解码和重新编码。 ImageWriteParam类( http://docs.oracle.com /javase/7/docs/api/javax/imageio/ImageWriteParam.html )允许您自定义压缩设置。


Having an ecommerce website, We have thousands of product images. On checking pagespeed on google it shows me something like this:

I was wondering, if there is any built in feature in Java or any third party library is available with which we can losslessly compress all the images that we host. Hence we can save few KBs of our customers.

On searching through internet I found few like punnypng and kraken which are paid, hence we do not have heavy image uploaded every month, subscribing to them is not worth. I would prefer any built in feature in Java or any open source third party library.

I came across JAI, but not sure about whether it addresses this problem or not. Anyone with hands-on experience with this?

P.S. We are using Java 8

解决方案

Have you looked at classes in the javax.imageio package (http://docs.oracle.com/javase/7/docs/api/javax/imageio/package-summary.html) ?

You can do decoding and re-encoding of the images. The class ImageWriteParam (http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageWriteParam.html) lets you customize the compression settings.

这篇关于优化图像 - 用Java无损压缩图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆