Introduction
ImageMagick is an open-source software suite that allows creating, editing, and converting images from the command line. Among its most used utilities is convert, a powerful command that supports dozens of operations: format change, resizing, cropping, rotation, filter application, layer combination, and much more. This article explains, step by step, how to take advantage of convert in a Linux environment to perform everyday image processing tasks without needing graphical interfaces.
Installing ImageMagick
In most Linux distributions, ImageMagick is available in the official repositories. On Debian/Ubuntu it is enough to run sudo apt update && sudo apt install imagemagick. On Fedora use sudo dnf install ImageMagick, while on Arch Linux the package is imagemagick and is installed with sudo pacman -S imagemagick. After installation, verify the version with convert --version; it should display information about the version and supported formats.
Basic syntax of the convert command
The generic form is convert [options] input_file output_file. Options can be placed before or after the input file, although it is recommended to place them before so they affect reading. Some frequent modifiers are -resize to change dimensions, -format to specify the output type, -quality to control JPEG compression, and -rotate to rotate the image. Each option accepts numeric or textual parameters, and you can chain as many as needed.
Common examples
- Resize to a specific width:
convert foto.jpg -resize 800x foto_redimensionada.jpg - Change format to PNG:
convert imagen.bmp -format png imagen.png - Crop a 300×200 pixel area from the top-left corner:
convert foto.jpg -crop 300x200+0+0 recorte.jpg - Rotate 90 degrees clockwise:
convert foto.jpg -rotate 90 foto_rotada.jpg - Apply a Gaussian blur effect:
convert foto.jpg -blur 0x8 foto_desenfocada.jpg - Convert to grayscale:
convert foto.jpg -colorspace Gray foto_gris.jpg
Advanced manipulation
- Create a thumbnail with borders:
convert foto.jpg -thumbnail 150x150 -bordercolor black -border 5 miniatura.jpg - Join several images in a single row:
convert img1.jpg img2.jpg img3.jpg +append fila.jpg - Create an animated GIF from a set of photos:
convert -delay 20 -loop 0 foto_*.gif animacion.gif - Add a text watermark:
convert foto.jpg -pointsize 30 -fill white -undercolor '#00000080' -gravity southeast -annotate +10+10 'Mi Marca' foto_marca.jpg - Extract a channel (e.g., only the red):
convert foto.jpg -channel R -separate canal_rojo.jpg - Optimize weight without losing perceptible quality:
convert foto.jpg -strip -interlace Plane -quality 85 foto_opt.jpg
Tips and tricks
- Use
-stripto remove unnecessary metadata and reduce file size. - When working with batches of files, combine
convertwith Bashforloops:for f in *.jpg; do convert "$f" -resize 1024x768 "redim_$f"; done - To preview effects without writing to disk, add
-write mpr:temp +deleteor usedisplayto show the result on screen. - Consult the full documentation with
man convertor visit the official sitehttps://imagemagick.org/script/convert.phpto explore lesser-known options such as-morphologyor-clut. - If you need to reproduce exactly the same results on different machines, make sure the ImageMagick version is the same, as some operators may change between major versions.
Conclusion
The convert command from ImageMagick positions itself as an essential tool for system administrators, developers, and any user who needs to process images quickly and reproducibly from the terminal. Its wide range of options allows performing everything from simple size changes to complex compositions and special effects, all without leaving the command-line environment. Mastering convert
This post is also available in ESPAÑOL.