Compress images

Requirements

There are many methods to compress images. I used the open source software ImageMagick.

One of the greatest benefits using ImageMagick is, that you don’t need to install anything – there’s a portable version.

In this example I used ImageMagick-7.1.0-4-portable-Q16-HDRI-x64.zip

goto the download page

Information

Goal

Each jpg file within a folder shall be compressed.

Setup

After you downloaded the latest portable version, unzip it in the desired location. ImageMagick is powerful but for this batch file we only need the “magick.exe” everything else can be deleted.

The Magic

This is nearly the whole magic.
This line will store every file name into the variable f and call the magick.exe with the defined parameters.

for %%f IN (*.jpg) DO magick convert "%%f" -quality 30 "%%f" 

Batch file

Folder structure
.
├── images                     
│ ├───image01.jpg              
│ ├───image02.jpg 
│ ├───image03.jpg  
├── compress.bat
├── magick.exe                    
├── start.bat                     
└── ...                      
start.bat

This file will call the other batch file with 1 parameter – the folder path where the images are located

@echo off
CALL compress images 
compress.bat

This file will call “magick.exe” in the same directory with parameters

@echo off
set path=%1
for %%f IN (%path%/*.jpg) DO magick convert "%path%/%%f" -quality 30 "%path%/%%f" 
Scroll to Top