When I use jpegtran on Windows, it’s very inconvenient. So I made a batch file for myself, which overwrites the original jpeg file with the new optimize jpeg file.
for %%a in (%*) do (
jpegtran -copy none -optimize -outfile !OutFile! %%a
for %%b in (!OutFile!) do set fileSize=%%~zb
if !fileSize! LSS %%~za (copy !OutFile! %%a>nul)
Bacicaly, the batch file replaces original jpeg files with new ones, but it leaves original files instead new ones when the new file is bigger than the original. This sometimes occurs if the original was created by some graphics editors. Around 100 files possible at one time. This maybe depends on cmd.exe ability itself, I think.
How to use the batch file:
- Copy & paste the above codes to a text editor, and save it as a batch file named ‘jpegtran.bat’ or something.
- Copy the batch file and jpegtran.exe to the same folder.
- Drag & Drop the jpeg files you want to optimize onto the batch icon.
- That’s it.
If you use the batch file, please remember the followings. This batch file makes overwriting, so it leaves no original files.
I optimized all jpeg files in my sites. Now, I have no suggestion about jpeg files from PageSpeed Insights. Clap, clap.
This post has a few visitors. So, I added some though I wrote this long before 😋.
You can place the folder (in which, jpegtran.exe and jpegtran.bat) anywhere in your PC. For your convenience, you should create a shortcut of jpegtran.bat on your Desktop. The shortcut ability equals jpegtran.bat itself.
You can do bulk actions for jpeg files are in some ranges by the batch file. Search jpeg files for the ranges and “Select All” then Drag&Drop.