Change JPEG compression settings in bulk

This article can be read in about 4 minutes.
PR

The purpose 

change the compression ratio of a large number of JPEGs all at once.

While there are web services and tools that can convert dozens of images, this time I’ll be converting hundreds to thousands.

PR

compression by cjpeg

Compression is performed using cjpeg, included in mozjpeg.

cjpeg is a command-line program; this application itself modifies the compression ratio of a single JPEG image. A batch file is created to modify the compression ratio of multiple JPEG files.

Download cjpeg

From the top of the page below, open “Assets” and look for links to mozjpeg-Vx.x.x-win-x64.zip and mozjpeg-Vx.x.x-win-x86.zip. (At the time of writing, V is 4.0.3.)

Releases · mozilla/mozjpeg
Improved JPEG encoder. Contribute to mozilla/mozjpeg development by creating an account on GitHub.

Download either mozjpeg-Vx.x.x-win-x64.zip or mozjpeg-Vx.x.x-win-x86.zip, depending on your system architecture.

Install cjpeg

Extract the downloaded zip file to a folder of your choice.

cjpeg.exe is located in this folder.

\shared\Release

Create bat

Create a batch file to run cjpeg on all .jpg files in a folder.

Create the following in Notepad and save it as cjpeg.bat.

mkdir "output"
for %%A in (*.jpg) do (
echo %%A
"<folder has cjpeg>\shared\Release\cjpeg.exe" -optimize -quality 90 -outfile "output\%%A" "%%A"
)

The deployment files will be changed to the folder where the zip file is extracted.

The “90” in “-quality 90” refers to JPEG quality. This can be changed if necessary (a value between 0 and 100, with 100 being the highest quality).

Execute bat

Copy cjpeg.bat to the folder containing the JPEG files you want to convert, and then double-click to run it.

PR

Result

An ‘output’ folder was created in the directory where the bat file was executed. Files with modified compression were saved in this folder, retaining their original names.

comment

Copied title and URL