ImageMagick Mogrify: Scale and Crop Multiple Images in One Command

When dealing with a lot of pictures, sometimes we want to make a common modification such as a change of resolution. In the case of multiple screenshots it is also common to crop all of the images at a fixed position (such as selecting only the same window). Here we will take a look at the command using ImageMagick mogrify.

Doing this job by hand, even just for three or four times, using the same parameters, is stressful and tiring, so we can ask for help to the terminal!

Mogrify is a command of the ImageMagick package and allows us to perform many operations on multiple images. In addition to scaling, resizing and cropping, mogrify can compress, convert, apply filter to images and much more.

Installation

For Fedora:

$ sudo yum install ImageMagick

For Ubuntu/Debian:

$ sudo apt-get install ImageMagick

 

Usage

The program overwrites the existing images, so, in order to prevent any unwanted modification, make a backup of the images or at least try the command on a sample image to make sure that it is the wanted modification.
Firstly, enter in the directory where the images that we want to modify are

$ cd folder_name

Then, say you want to scale the pictures to a resolution of 640×480:

$ mogrify -scale 640×480 *.*

(note: if using the wildcard *.* , every single file in the folder will be modified by the command, so make sure that the folder contains only the files you want to modify or use different wildcards as *.jpg or e.g. *-2012.jpg)

If you want to scale the pictures keeping the aspect ratio, specify only the length in pixels and the height will be adjusted to keep constant the aspect ratio:

$ mogrify -scale 640 *.*

Or using the same argument for the height instead of the width:

 $ mogrify -scale x480 *.*

Or can also use a percentage of the original size, so if you want to halve the resolution:

$ mogrify -scale 50% *.*

Or you can even modify only pictures bigger (or smaller) than the specified resolution and keep the others unchanged, respectively:

$ mogrify -scale ‘640×480>’ *.*

$ mogrify -scale ‘640×480<‘ *.*

If you want to crop pictures in a window of 300×200 starting at pixels x=0 and y=100 where x is the offset in length from left to right and y is the offset in height from top to bottom, you need to use another option.
Since it is difficult to know the offset precise values a priori using gimp (a graphical editor) to take these values from the cursor position or selection can help. Then, use:

$ mogrify -crop 300×200+0+100 *.*

If you want to compress images, use:

 $ mogrify -compress JPEG -quality 85 *.jpg

where JPEG is the compression type and 85 is the quality for JPEG compression, which varies from 0 (lowest) to 100 (highest).

Or convert images from gif to jpeg format:

$ mogrify -format jpg -quality 85 *.gif

And rotate by an angle, e.g. 90 degrees:

$ mogrify -rotate 90 *.*

Or if you want to rotate the image only in specific occasions, as if height is bigger than length (e.g. 480×640) (and viceversa), use, respectively:

$ mogrify -rotate ’90>’ *.*

$ mogrify -rotate ’90<‘ *.*

Useful Links

Check out the official page of ImageMagick on Mogrify here, where you can find with more detail all the options of mogrify.

Read More Post

STAY CONNECTED

Most Popular

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know
17 Dec

Why Serviced Apartments Are the Perfect Choice for Long-Term Stays in Singapore – Everything You Need to Know

If you’re heading to Singapore for a few weeks or many months, maybe for work or study or just to

Manifesting Your Dream Career: Finding Your Passion And Purpose
01 Aug

Manifesting Your Dream Career: Finding Your Passion And Purpose

Are you passionate about finding your dream career? Manifesting can help you align your career with your passions and purpose.

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service
27 Feb

Revolutionizing Your Ride: Expert Auto Service At Carolina Auto Service

Finding a reliable auto service provider is paramount in the bustling world of vehicle maintenance and repair. That's where Carolina

Floratam: The Robust Grass Solution From Council Growers SOD
25 Jan

Floratam: The Robust Grass Solution From Council Growers SOD

Floratam grass, a popular St. Augustine variety, has become a go-to choice for homeowners and landscapers seeking a lush, durable

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair
25 Jan

Carolina Mobile Autoservice: Your Go-To For Expert Brake Service Repair

For vehicle owners, the braking system is among the most critical components for safety and performance. Carolina Mobile Autoservice, a

Safeguarding Your Property: Expert Water Damage Services By MBC Capital
24 Jan

Safeguarding Your Property: Expert Water Damage Services By MBC Capital

Water damage can significantly impact homes and businesses, often leaving a trail of destruction and disruption in its wake. Understanding