Resize an image from the Linux terminal | Opensource.com

Resize an image from the Linux terminal

Shrink an image from your terminal with the ImageMagick convert command.

Old camera blue
Image by : 
Internet Archive Book Images. Modified by Opensource.com. CC BY-SA 4.0
x

Subscribe now

Get the highlights in your inbox every week.

ImageMagick is a handy multipurpose command-line tool for all your image needs. ImageMagick supports a variety of image types, including JPG photos and PNG graphics.

Resizing images

I often use ImageMagick on my webserver to resize images. For example, let's say I want to include a photo of my cats on my personal website. The photo from my phone is very large, about 4000x3000 pixels, at 3.3MB. That's much too large for a web page. I use the ImageMagick convert tool to change the size of my photo so that I can include it on my web page. ImageMagick is a full suite of tools, one of the most common is the convert command.

The ImageMagick convert command uses this general syntax:

convert {input} {actions} {output}

To resize a photo called PXL_20210413_015045733.jpg to a more manageable 500-pixel width, type this:

$ convert PXL_20210413_015045733.jpg -resize 500x sleeping-cats.jpg

The new image is now only 65KB in size. 

You can provide both width and height dimensions with the -resize option. But, by providing only the width, ImageMagic does the math for you and automatically retains the aspect ratio by resizing the output image with a proportional height.

Install ImageMagick on Linux

On Linux, you can install ImageMagick using your package manager. For instance, on Fedora or similar:

$ sudo dnf install imagemagick

On Debian and similar:

$ sudo apt install imagemagick

On macOS, use MacPorts or Homebrew.

On Windows, use Chocolatey.

Polaroids and palm trees

Here's how I use ImageMagick to make photo grids for my social media posts.
Python in a tree

A quick explanation of how to resize images in Python while keeping the same aspect ratio.

About the author

photo of Jim Hall
Jim Hall - Jim Hall is an open source software advocate and developer, best known for usability testing in GNOME and as the founder + project coordinator of FreeDOS. At work, Jim is CEO of Hallmentum, an IT executive consulting company that provides hands-on IT Leadership training, workshops, and coaching.