Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a way in which I can do a lossless compression of all images in a directory in a batch process. I don't want images to loose quality.

I am running this website, for this if you check in google's pagespeed tool, it suggests you to optimize images using lossless compression. For new product's images I can make changes in my algorithm of image saving but for existing images of products I need a way by which I can run a command which can do lossless compression for all images of products residing in a directory.

EDIT: Please see this site report

Here you can find optimize images point in 5th suggestion, there you can see it is listing number of jpeg images to losslessly compress. If you optimize your images from an online image optimization utility like then this warning is gone.

share|improve this question
What do you mean by "lossless compression"? It seems that right now your images are JPEGs, which is a lossy format... – fkraiem May 26 '14 at 19:08
@fkraiem please see edit – Abhi May 27 '14 at 4:11

I do not think Google means you to compress the images. That simply will not work.

Instead it is suggested to switch on compression in your webserver.

See here: Google's PageSpeed help on Compression

share|improve this answer
server compression is already on, please see this link here you will find optimize images suggestion that is 5th number suggestion, to losslessly compress images to decrease size of image – Abhi May 27 '14 at 4:03
@Abhi : Looking at the website you link to and their 5th suggestion, I can understand that they would advise to use .png instead of .gif. It's always a better idea to use .png. But how that site thinks that a .jpg is a lossless version of jpeg is beyond me. Next, given the improvement gain I wouldn't bother with that. Their 1st and 2nd suggestions might be more interesting, but when I then look at the absolute gains predicted (being at the kilobyte-level; remember that most people have megabyte/s connections) and considering the overall load-time of your site I wouldn't worry too much. – Mausy5043 May 28 '14 at 14:37

If you want to further compress your images or convert them to a different format which has a better compression ratio, you might want to look at the convert command.

It has loads of options.

share|improve this answer

jpegoptim performs lossless compression of JPEG images

optipng performs lossless compression of PNG images

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.