LinuxCommandLibrary

magick-mogrify

Batch process and modify image files

TLDR

Resize all JPEG images in the directory to 50% of their initial size

$ magick mogrify -resize [50%] [*.jpg]
copy

Resize all images starting with DSC to 800x600
$ magick mogrify -resize [800x600] [DSC*]
copy

Convert all PNGs in the directory to JPEG
$ magick mogrify -format [jpg] [*.png]
copy

Halve the saturation of all image files in the current directory
$ magick mogrify -modulate [100,50] [*]
copy

Double the brightness of all image files in the current directory
$ magick mogrify -modulate [200] [*]
copy

Reduce file sizes of all GIF images in the current directory by reducing quality
$ magick mogrify -layers 'optimize' -fuzz [7%] [*.gif]
copy

Display help
$ magick mogrify -help
copy

SYNOPSIS

magick-mogrify [options] input-image...

PARAMETERS

-resize <geometry>
    Resizes the image. Examples: 200x150 (exact fit), 50% (percentage), x100 (height to 100px).

-crop <geometry>
    Crops the image. Example: 100x100+10+10 (width x height + x_offset + y_offset).

-rotate <degrees>
    Rotates the image by the specified degrees clockwise.

-format <format>
    Converts the image to the specified format (e.g., jpg, png, webp). Note: This also changes the file extension.

-quality <value>
    Sets the compression quality for lossy formats (0-100).

-strip
    Removes all profiles, comments, and other non-image data from the image.

-auto-orient
    Automatically rotates the image based on EXIF orientation data (e.g., from digital cameras).

-path <directory>
    Writes modified images to the specified directory instead of overwriting originals. This is a crucial safety option.

-monochrome
    Transforms the image to black and white.

-gamma <value>
    Adjusts the image's gamma level. A value greater than 1 lightens, less than 1 darkens.

-blur <radiusxsigma>
    Applies a blur effect to the image. radius is the blur radius, sigma is the standard deviation.

-sharpen <radiusxsigma>
    Sharpens the image. radius is the blur radius, sigma is the standard deviation.

-verbose
    Displays detailed information about image processing steps to standard output.

DESCRIPTION

The magick-mogrify command, a powerful utility from the ImageMagick suite, is designed for in-place image processing. Unlike its counterpart magick-convert, which creates a new image file, magick-mogrify directly modifies and overwrites the original image file or files provided as arguments. This makes it exceptionally useful for batch processing and automated workflows where the original files are intended to be replaced with their processed versions.

It supports a vast array of image manipulation operations, including resizing, cropping, rotating, applying various visual effects, adjusting colors, and changing image formats. Due to its destructive nature (overwriting the original files), extreme caution is advised when using magick-mogrify. Users should always ensure backups are in place or utilize options like -path to output modified images to a different directory, especially during initial testing or when processing valuable data. Its efficiency in modifying files directly makes it a staple for server-side image processing tasks and command-line automation.

CAVEATS

magick-mogrify directly modifies and overwrites the original image files. This means that once an operation is performed, the original image data is permanently lost unless a backup has been made or the -path option is used to save changes to a different location. Always exercise extreme caution and consider testing on copies or using a dedicated output directory to prevent unintended data loss, especially when processing critical images or large batches. It's also resource-intensive for very large images or extensive batch operations, so monitor system resources.

SAFETY FIRST: ALWAYS BACK UP OR USE <I>-PATH</I>

Given magick-mogrify's destructive nature, it is highly recommended to either create backups of your original images before running the command or to use the -path <directory> option. The -path option directs all modified images to a specified directory, leaving the originals untouched. This is invaluable for testing and ensuring the desired output before committing to in-place modifications.

CHAINING OPERATIONS

Multiple operations can be chained together in a single magick-mogrify command. ImageMagick processes these options sequentially from left to right. For example, magick-mogrify -resize 50% -gamma 0.5 -format png *.jpg will first resize, then adjust gamma, and finally convert the format for all JPEG files, overwriting them as PNGs. Understanding this execution order is crucial for achieving predictable results.

HISTORY

The mogrify command is an integral part of the ImageMagick software suite, which has a long history dating back to 1987. ImageMagick was originally developed by John Cristy at DuPont. Over the years, the suite evolved from a collection of individual command-line utilities (like convert, mogrify, identify, display) into a more unified system. Modern versions often consolidate these functionalities under a single magick executable, where mogrify is invoked as magick mogrify. Its dedicated purpose of in-place modification makes it a distinct and powerful tool within the ImageMagick ecosystem, emphasizing efficiency for batch processing by avoiding the overhead of creating new files.

SEE ALSO

magick(1): The main ImageMagick command, often acting as a dispatcher for various sub-commands like `mogrify`., magick-convert(1): Converts an image from one format to another, creating a new file rather than overwriting the original., identify(1): Describes the format and characteristics of one or more image files (e.g., dimensions, color depth)., display(1): Displays an image or image sequence on a graphical display.

Copied to clipboard