ImageMagick: How to Change Image DPI

Updated

Learn how to change the DPI of an image using ImageMagick

ImageMagick: How to Change Image DPI

Before we start, make sure you have ImageMagick installed on your computer and your image ready in a folder. If you don't have it yet, run this command:

brew install imagemagick

First, open your terminal and navigate to the folder that has your image. To change the DPI without touching the pixels, run this command:

magick input.jpg -units PixelsPerInch -density 300 output.jpg

Just remember to replace input.jpg with your actual filename. The -density 300 option sets the new DPI, and -units PixelsPerInch makes sure ImageMagick reads that number as inches instead of centimeters. This only changes the DPI setting, so the pixel size stays exactly the same.

To make sure everything worked, run this command:

magick identify -format "%wx%h | %x x %y %U\n" output.jpg

It prints the pixel size, the DPI and the units, something like 1920x1280 | 300 x 300 PixelsPerInch.

One more tip: if you want the pixels to change too, swap -density for -resample. Running -resample 150 on a 300 DPI image cuts the width and the height in half, so it still prints at the same physical size.