Skip to content

What is mogrify Linux command?

mogrify is a powerful command-line tool in Linux used for batch processing images. It allows users to resize, rotate, flip, convert, and apply various effects to multiple images at once, making it a handy tool for image manipulation tasks.

mogrify Syntax:

Terminal window
mogrify [options] [parameters]

mogrify Options:

OptionDescription
-crop crop an image to the specified geometry
-resize resize the image
-rotate rotate the image by the specified degrees
-flipflip the image vertically
-flopflop the image horizontally
-quality set the image quality

Parameters:

ParameterDescription
file(s)The image file(s) to be processed

mogrify Command Usage Examples:

Resize Images to a Specific Width

Terminal window
mogrify -resize 800x input_image.jpg

Resizes the input_image.jpg to have a width of 800 pixels while maintaining the aspect ratio.

Convert PNG Images to JPEG Format

Terminal window
mogrify -format jpg *.png

Converts all PNG images in the current directory to JPEG format.

Add Border to Images

Terminal window
mogrify -bordercolor black -border 20x20 *.jpg

Adds a black border of 20 pixels around all JPEG images in the current directory.

Rotate Images

Terminal window
mogrify -rotate 90 *.jpg

Rotates all JPEG images in the current directory by 90 degrees clockwise.

Convert Images to Grayscale

Terminal window
mogrify -type Grayscale *.jpg

Converts all JPEG images in the current directory to grayscale color mode.

How do I resize an image using mogrify in Linux?

To resize an image using mogrify in bash, execute the following command:

Terminal window
mogrify -resize 50% image.jpg

How can I rotate an image with mogrify in Linux?

To rotate an image using the mogrify command in bash, you can use the following command:

Terminal window
mogrify -rotate 90 image.jpg

How do I convert images to grayscale with mogrify in Linux?

To convert images to grayscale with mogrify in bash, you can run the following command:

Terminal window
mogrify -type Grayscale image.jpg

How can I add a border to an image using mogrify in Linux?

To add a border to an image with mogrify in bash, use the following command:

Terminal window
mogrify -bordercolor black -border 20x20 image.jpg

How do I crop an image using mogrify in Linux?

To crop an image with mogrify in bash, you can use the following command:

Terminal window
mogrify -crop 100x100+50+50 image.jpg

How can I blur an image with mogrify in Linux?

To blur an image using mogrify in bash, execute the following command:

Terminal window
mogrify -blur 0x8 image.jpg

How do I add text to an image using mogrify in Linux?

To add text to an image with mogrify in bash, you can use the following command:

Terminal window
mogrify -fill white -undercolor '#00000080' -pointsize 36 -annotate +100+100 'Example Text' image.jpg

Applications of the mogrify command

  • Batch resize images
  • Batch rotate images
  • Batch convert image formats
  • Batch add effects or filters to images
  • Batch compress images