ImageMagick - Manipulate images with command lines

Last update on April 12, 2009 04:48 PM by jak58
Published by jak58

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).)
Best answers for « ImageMagick Manipulate images with command lines » in :
Creating an ISO image under Linux Show Creating an ISO image under Linux Create ISO image(which we will name) a disc in a CD-ROM drive(/dev/cdrom) is quite simple : dd if=/dev/hdd of=mycd.iso
Firefox+Yubnub:The web command line Show Firefox +Yubnub: The web command line Installation of YubNub in Firefox http://yubnub.org/ is a search engine having command lines (typing) for actions. For example, type gim chats for searching image chats on google. This...
Start/stop a service using command line Show Start/stop a service using command line The netsh tool (netsh.exe) can automate the startup or shutdown of a service through the following command line: To start a service: Net start name_of_service To stop a service:...
Enable/disable a device from the command line ShowEnable/disable a device from the command line Install Devcon Display all the devices in the system Enable/disable the device Other devices Here is a trick that allows you to enable / disable a device from the command line in XP....
[Windows XP] Repairing the network connection using command line Show[Windows XP] Repairing the network connection using command lines Under Windows XP there is a small feature allowing you to repair a network connection. Go to the Network Connections options in Control panel (Control Panel / Network...
List of open ports in command line ShowList of open ports in command line Whether you're running Windows or Linux / Unix, the following command in (console) will display the list of open ports on your computer: netstat -a For the use of advanced graphics tools, see What...
Download Avira AntiVir Personal free for Linux / FreeBSD / OpenBSD / Solaris ShowFor Linux / FreeBSD / OpenBSD / Solaris Avira AntiVir PersonalEdition Classic is a very good and free antivirus which reliably protects your private computer against dangerous viruses, worms, Trojans, rootkits and costly dialers.
Download Some PDF Image Extract ShowDocuments PDF can include of the text, of graphs, pictures but also pictures. Given that it is not possible to change contents, the same is true of for the extraction of a picture of the contents of the document. Some Colorful PDF Extract is a tool...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...
Network tests and diagnostics ShowTesting the IP configuration Before doing anything else, you are advised to check the computer's IP configuration. Windows systems offer a command-line tool, called ipconfig, that lets you find out your computer's IP configuration. The output of...
UNIX system - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence its name "shell". The shell therefore acts as an intermediary between the operating system and the user using command lines...