Image Optimization - Lossless Image Compression in Java

With an e-commerce site, we have thousands of product images. When checking pages on google, it shows me something like this:

enter image description here

I was wondering if there is a built-in function in Java or some third party library with which we can losslessly compress all the images we host. Hence, we can save several KB for our customers.

When searching on the internet, I found a bit like punnypng and kraken that pay, so we don't have an image uploaded every month, no subscription worth. I would prefer any built-in function in Java or any open source third party library.

I ran into JAI but not sure if it solves this problem or not. Anyone with practical experience with this?

PS We are using Java 8

+3


source to share


3 answers


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



You can decode and re-encode images. The ImageWriteParam class ( http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageWriteParam.html ) allows you to customize the compression settings.

+2


source


~ 600 KB jpeg images are quite large for the screen, although not for printing. Having multiple images on a page would mean reducing the size of the thumb. And provide a separate product page with a higher resolution, say a 600KB JPEG. Standard ImageIO is sufficient for conversion, see @NicolaFerraro.

Faster page loading can be achieved on a multi-image overview page by storing small images in one large image. PNG can then be appriopriate to prevent JPEG artifacts.



To provide a higher resolution for printing, you can use the CSS media setting.

0


source


Check the thumbnailator . This is great for creating smaller images from larger images.

Also, you should think about when you take these small images. On every call on first call (keeping the cache), ...

0


source







All Articles