What is the Basic Syntax of ImageMagick Convert?

ImageMagick’s convert command is a powerful CLI tool used for image manipulation, including converting file formats, resizing images, and applying various visual effects. Understanding its basic syntax allows users to efficiently process single or batch images directly from the terminal. This guide covers the essential structure of the command, common options, and practical examples to get you started.

The Standard Command Structure

The fundamental syntax for the convert command follows a specific logical sequence. You must specify the input image, the operations you want to perform, and the final output destination.

convert [input_options] input_file [image_processing_options] output_file

Common Syntax Examples

ImageMagick determines the output format based on the file extension you provide at the end of the command. Here are the most frequent use cases for the basic syntax.

1. Converting File Formats

To change an image from one format to another without changing its dimensions or quality, simply change the extension of the output file.

convert input.png output.jpg

2. Resizing an Image

To alter the dimensions of an image, use the -resize option followed by the desired width and height in pixels.

convert input.jpg -resize 800x600 output.jpg

Note: By default, ImageMagick maintains the original aspect ratio. If you want to force the image to exact dimensions regardless of aspect ratio, append an exclamation point to the geometry: 800x600!.

3. Adjusting Image Quality

When converting to lossy formats like JPEG, you can control the compression and quality level using a scale from 1 to 100.

convert input.png -quality 85 output.jpg

4. Rotating an Image

You can rotate an image clockwise by specifying the degrees of rotation using the -rotate option.

convert input.jpg -rotate 90 output_rotated.jpg

Order of Operations Matters

In ImageMagick, the sequence of your arguments is crucial. The tool reads the command from left to right. If you place image processing options before the input file, they may either be ignored or applied incorrectly depending on the version of ImageMagick you are running. Always ensure your source file comes before the transformations you wish to apply to it.