Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimize images - Losslessly compress images in Java

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

enter image description here

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

like image 334
Abhi Avatar asked Nov 01 '22 12:11

Abhi


1 Answers

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.

like image 182
Nicola Ferraro Avatar answered Nov 15 '22 04:11

Nicola Ferraro