Lei Wu, Web Developer

Keeping simple things simple.

Optimize Your Images With Lossless Compression

One way to make your web pages load faster is to use lossless compression.

On Linux there’s a tool called “jpegoptim” to losslessly optimize JPEG files. You can install using apt-get or yum.

Here’s how to optimize all jpg files in a directory:

find /jpg_directory/ -maxdepth 1 -type f -name "*.jpg" -exec jpegoptim --strip-all {} \;

You can remove -maxdepth 1 if you want to process the JPEGs in the subfolders recursively.

Similarly, the tool to optimize PNG files is “optipng”.