How to Optimize All JPG and PNG Files in a Folder Using the Windows Command Line

Images on the internet should always be optimized where possible to reduce the load time of your websites. Of course the best solution is to use a CDN but sometimes for whatever reason like me you inherit some folders full of unoptimized images you can run the following commands to reduce the load on your server. These could also be added to batch files and run in the scheduler if required.


  1. Download [jpegtran.exe] (
  2. Run the following command:
for /R "C:\yourimagesfolder" %I in (*.jpg) do @"C:\yourdownloadfolder\jpegtran.exe" -copy none -optimize -progressive -outfile %I %I


  1. Download [optipng.exe] (
  2. Run the following command
for /R "C:\yourimagesfolder" %I in (*.png) do @"C:\yourdownloadfolder\optipng.exe" -o7 -strip all %I
comments powered by Disqus