Optimize images for the web in bulk

Optimizing and loss-less compressing images is one of those items that always pops up when analyzing your website with Google PageSpeed Insights. Images have to be loss-less compressed to save many bytes of data and thus bandwidth. This speeds up the download time of your website. But, how do we optimize images for the web? Or, what if I have hundreds of images that needs optimization? Let’s optimize and loss-less compress images in bulk, read on.

Optimize images for the web in bulk with OptiPNG

In this post we optimize PNG images as example. The same goes for loss-less compressing and optimizing JPEG images, you only need another tool (jpegtran or jpegoptim).

Google PageSpeed Insights already mentions the tools, we only have to download and use them.

So, go ahead and download OptiPNG. There is no installation required, it’s a run once executable for the command line.

If you are familiar with the command line, for example on Windows 7 and higher, you can very easily execute OptiPNG with its default settings on all your PNG files in a directory:

D:\Dev\sites>
 FOR /F %I in ('dir /b/s *.png')
 do @c:\optipng-0.7.4-win32\optipng.exe %ICode language: PowerShell (powershell)

This will loss-less compress and optimize all PNG images in bulk, found within d:\dev\sites\ and recursively into sub directories, making your images and website-footprint smaller, resulting in a faster download of your website.

OptiPNG: lossless compressing images on the fly

The following command lossless compresses all PNG files recursively, from within my content directory:

FOR /F %I in ('dir /b/s *.png') DO @C:\Temp\optipng-0.7.5-win32\optipng.exe -o5 %ICode language: PowerShell (powershell)

Are you looking for rock solid, eco-friendly, .NET hosting? Look no further! UmbHost offers powerful hosting services for websites and businesses of all sizes, and is powered by 100% renewable energy!

Jan Reilink

Hi, my name is Jan. I am not a hacker, coder, developer or guru. I am merely an application manager / systems administrator, doing my daily thing at Embrace - The Human Cloud. In the past I worked for clidn and Vevida. With over 20 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization. I blog at https://www.saotn.org.

2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
10/01/2017 22:17

You can also run just:
c:\optipng-0.7.4-win32\optipng.exe *.png