ImageMagick - Manipulate images with command lines
ImageMagick is a powerful command line tool that allows you to manipulate images.
The advantage of this tool is that it allows:
- Automate work on images (this avoids having to do some manipulation in Photoshop or Gimp).
- Implement operations and conversion of a blow to hundreds of images at once.
- To convert between different image formats
- To create images on the go
- To be incorporated into your programs and scripts (this allows your programs and scripts to generate and manipulate images on the fly). For example, it is usable with PHP to generate images.
This program available for Windows and Linux.
Install ImageMagick on Windows
- 1. Download ImageMagick
- 2. Install it. During installation, be sure to properly check the "Update executable search path"
- 3. Close and re-open your session (or restart the computer). This step is necessary for the path (PATH) ImageMagick is taken into account.
To verify the installation, open an MS-DOS window and type: convert--version
You should see
Version: ImageMagick 6.3.3 04/08/07 Q16 file:///usr/local/share/doc/ImageMagick
6.3.3/index.html
Copyright: Copyright (C) 1999-2007 ImageMagick Studio LLC
Convert an image from one format to another
- Convert an image in bmp png:
convert image.bmp image.png
- Convert an image in jpg bmp progressive, quality 70%:
convert image.bmp -interlace line -quality 70 image.png
The
-quality xoption allows you to adjust the quality of JPEG.
The
-interlace line can create JPEG progession.
Prepare a photo for the web
The operations are:
- Reduce the image resolution (eg, switch from 2592x1944 (5 Mega-pixels) to 800x600)
- Progressive JPEG compressed (for an immediate display of the image in the page)
- Delete unnecessary information (comments, EXIF ...: This information (miniature, name of the software that created this file, camera settings when shooting (EXIF), etc..) are ignored by browsers.
convert maphoto.jpg -resize 800x600 -strip -quality 50 -interlace line imageweb.jpg
- -resize AxBresizes the image to the desired size.
- -strip removes additional information (EXIF, comments ...)
- -quality 50 can select a quality of 50% for the JPEG compression.
- -Interlace line creates a progressive JPEG.
Put a text on an image
To avoid getting stung a high resolution image without permission, you can add a text on the entire surface of the image.
convert -size 150x50 xc:none -matte -pointsize 20 -fill #ffffff80 -draw "text 10,30 'My copyright'" miff:- | composite -tile - photo.jpg resultat.jpg
The removal of this mark is too much work for the theft of the image is interesting.
Apply a transformation to a group of images
To simplify the previous explanations, examples were given on a single image.
But it is possible to perform these operations at once on many images.
Recompress JPEG images in the current directory as 70 (exit in the output sub-directory):
FOR %%G IN (*.jpg) DO convert "%%G" -strip -quality 70 -interlace plane "output/%%G"
Convert all files from .BMP to. JPG :
FOR %%G IN (*.bmp) DO convert "%%G" -strip -quality 70 -interlace plane "%%~nG.jpg"
(~ n means that it only takes the filename (without the extension).)