LinuxCommandLibrary

convert

Convert image file formats

TLDR

View documentation for the original command

$ tldr magick convert
copy

SYNOPSIS

The convert command follows a flexible syntax, generally structured as:

convert [input_options] input_file [output_options] output_file

Or for operations involving multiple images:

convert image1 image2 ... [operation] output_file

Options can be placed before the input file to apply globally, or between input and output files to apply specific effects or transformations to the processing pipeline.

PARAMETERS

-resize WxH
    Resizes the image to the specified width (W) and height (H). Modifiers like 'WxH!' (exact size), 'WxH>' (if larger), or 'WxH<' (if smaller) can be appended.

-rotate degrees
    Rotates the image by the given number of degrees clockwise.

-crop WxH+X+Y
    Extracts a rectangular region from the image, starting at offset (X,Y) with dimensions Width (W) and Height (H).

-quality value
    Sets the compression quality for formats like JPEG (0-100) or PNG (0-9), where higher values mean better quality/larger file size.

-format format
    Explicitly specifies the output image format (e.g., 'png', 'jpeg', 'gif', 'webp'). This often overrides the format inferred from the output filename's extension.

-strip
    Removes all profiles (e.g., EXIF, IPTC, XMP) and comments from the image, typically reducing file size.

-auto-orient
    Automatically rotates the image based on its EXIF orientation tag, if present, ensuring it appears correctly oriented.

-fill color
    Sets the color for drawing operations (e.g., text, shapes) or used as a background color.

-annotate geometry text
    Adds text to the image at a specified geometry (position and optional rotation).

-monochrome
    Transforms the image into a grayscale image using only black and white pixels, effectively binarizing it.

-background color
    Specifies the background color used when an image is cropped, resized with expansion, or composited on a canvas.

-alpha option
    Controls the alpha channel of the image, with options like 'on', 'off', 'set', 'remove', 'extract', to manage transparency.

DESCRIPTION

convert is a fundamental command-line utility from the ImageMagick suite. It serves as a versatile tool for processing digital images, enabling users to transform formats (e.g., JPEG to PNG, TIFF to WebP), resize dimensions, rotate orientations, crop sections, and apply various artistic or technical effects.
Its strength lies in supporting a vast array of image formats and its non-interactive nature, making it ideal for scripting and batch operations on servers or local systems. From simple format changes to complex image compositions, convert provides extensive control over image attributes and pixel data.

CAVEATS

The convert command, while highly powerful, can be resource-intensive, especially when processing large images or performing complex operations in batch.
Its extensive range of options contributes to a steep learning curve, and understanding the order of operations, especially with multiple inputs or parenthesized commands, requires careful attention.
Crucially, with the release of ImageMagick 7 (IM7), the standalone convert command is considered deprecated in favor of the unified magick command. While convert often remains available for backward compatibility, new development should ideally use magick.

PERFORMANCE CONSIDERATIONS

For very large-scale or high-performance image processing pipelines, while convert is powerful, users might consider alternatives like GraphicsMagick (a fork of ImageMagick 5) or dedicated image processing libraries that might offer different performance characteristics for specific tasks or environments.

SCRIPTING UTILITY

Due to its robust command-line interface, convert is extensively used in shell scripts, cron jobs, and server-side applications for automated image handling. Common uses include generating thumbnails, applying watermarks, converting image formats for web optimization, or creating dynamic image content.

HISTORY

The convert command has been a cornerstone of the ImageMagick suite since its inception in 1990. Initially developed by John Cristy at DuPont, ImageMagick and its utilities like convert quickly became an industry standard for command-line image processing due to their versatility and cross-platform compatibility.
It gained significant traction in web development for on-the-fly image manipulation and server-side automation.
With the major architectural changes introduced in ImageMagick 7, released around 2016, the design philosophy shifted towards a unified magick command. Consequently, convert and other separate utilities (like mogrify, identify) are now symbolically linked or aliased to magick for backward compatibility, marking a transition in its historical usage.

SEE ALSO

magick(1), mogrify(1), identify(1), display(1), composite(1), montage(1)

Copied to clipboard