From pagespeed I am getting only image link and possible optimizations in bytes & percentage like, Compressing and resizing https://example.com/…ts/xyz.jpg?036861 could save 212KiB (51% reduction). Compressing https://example.com/…xyz.png?303584508 could save 4.4KiB (21% reduction).
For an example I have image of size 300kb and for this image pagespeed is displaying 100kb & 30% of reduction.
This is only for one image but I am sure I will have lots of images for compression. so how can I compress image by passing bytes or percentage as a parameter or using anyother calculations in java (by using API or image-processing Tool) so,that I can get compressed version of image as suggested by google.
Thanks in advance.
There is colour compression ("compression quality") and there is resolution compression ("resizing"). Fujy's answer deals with compression quality, but this is not where the main savings come from: the main savings come from resizing down to a smaller size. E.g. I got a 4mb photo to 207K using the maximum compression quality using fujy's answer, and it looked awful, but I got it down to 12K using a reasonable quality but a smaller size.
So the above code should be used for "compression quality", but this is my recommendation for resizing:
https://github.com/rkalla/imgscalr/blob/master/src/main/java/org/imgscalr/Scalr.java
I wish resizing was part of the standard Java libraries, but it seems it's not, (or there are image quality problems with the standard methods?). But Riyad's library is really small - it's just one class. I just copied this class into my project, because I never learnt how to use Maven, and it works great.
You can use Java
ImageIO
package to do the compression for many images formats, here is an exampleYou can find more details about it here
Also there are some third party tools like these
EDIT: If you want to use Google
PageSpeed
in your application, it is available as web server module either for Apache or Nginx, you can find how to configure it for your website herehttps://developers.google.com/speed/pagespeed/module/
But if you want to integrate the
PageSpeed
C++ library in your application, you can find build instructions for it here.https://developers.google.com/speed/pagespeed/psol
It also has a Java Client here
https://developers.google.com/api-client-library/java/apis/pagespeedonline/v1