Munzir Alradi
ع
Munzir Alradi
Home About Services Work Blog Tutorials Contact Light Tunnel العربية
Tools

Batch Image Processing with ImageMagick

Resizing and converting a hundred documentation photos in one command instead of a hundred clicks.

2021 2 min read 11 photos
A photo icon with a second frame behind it, on a teal grid

ImageMagick

ImageMagick® is am open source software that makes you able to create, edit, compose, or convert digital images.It can read and write images in a variety of formats (over 200) including PNG, JPEG, GIF, WebP, HEIC, SVG, PDF, DPX, EXR and TIFF. ImageMagick can resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.

The Image Magick wizard casting stars with his wand

Download ImageMagick

what makes image magick the best choice is

  • free and open source
  • working in cross platform
  • work in command line

you can download image magick from [here]{https://imagemagick.org/script/download.php#windows)

The Linux, Windows, Mac Os X and iOS links circled on the ImageMagick site

Add ImageMagick to path

after downloading image magic now its time install it and to add it to the path in order to use it in command line

Accepting the license agreement in the ImageMagick installer

here to make sure that you check the option for adding it to path ,

  • if you want also to convert video in command line you can check installing ffmpeg
Ticking Add application directory to your system path

then click install

The Ready to Install summary, just before clicking Install

image magicks in command line

to use image magicks from command line follow these steps

  • First cd to the file contain all the images and ls to see the content
  • ls to see the folder content ( if you know the image name you don’t need ls )
cd into the folder of pictures, then ls to list it

Identify

You can call imagemagick in the command line by typing magick before and task here I used the command identify to describe the format and characteristics of one or more image files. 1.png PNG 773x409 773x409+0+0 8-bit sRGB 86243B 0.000u 0:00.005

By default, magick identify provides the following output: Filename[frame #] image-format widthxheight page-widthxpage-height+x-offset+y-offset colorspace user-time elapsed-time

The file is PNG format The size in pixels is 773x409 and each pixel is 8-bit The color profile is sRGB

magick identify on one PNG, and the line it prints back

Resize images

  • first choose the image you want to resize
  • then To resize the image we can use convert –resize ( then here we specify the size, for web 1280x720 is good size )

magick convert -resize 1280x720

Resizing a single file to 1280x720 with magick convert

Now I resized all my image and put them in a file to be uploaded and

The same resize command repeated file by file

images quality

also I can make the quality by type –quality and I can notice here that the image size drubbed from 224 KB to 226 KB

Frames 01–02

    The resize run with -quality 65 (resized-image14.png) and without it (resized-image13.png)
    Windows Properties: resized-image13.png at 224 KB, resized-image14.png at 226 KB

References

Anatomy of the Command-line

Command-line Tools

Command-line Options

Type to search