How to Change Image DPI with ImageMagick Convert?

Changing the DPI (dots per inch) or resolution of an image using ImageMagick’s convert command is a straightforward process that involves modifying the image’s metadata or resubmitting its pixel dimensions. This article provides a quick overview of how to use the -density and -resample flags to alter image resolution for both print and digital display, ensuring your images meet specific quality requirements without losing clarity.

Understanding Density vs. Resampling

When altering image resolution in ImageMagick, you must choose between changing the metadata (density) or changing the actual pixel count (resampling).

How to Change DPI Metadata Only

If you need to change the DPI for print purposes but want to keep the exact same pixel dimensions, use the -density flag followed by your desired resolution. You should also include the -units flag to specify pixels per inch.

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

In this example, input.jpg is converted to output.jpg with a metadata setting of 300 DPI, while the underlying pixel grid remains completely untouched.

How to Resample the Image Resolution

If you want to change the DPI and have ImageMagick automatically resize the pixel dimensions of the image to match that new resolution, use the -resample flag.

convert input.jpg -units PixelsPerInch -resample 72 output.jpg

This command is highly useful when optimizing large, high-resolution print images for web display by downsampling them to standard screen resolutions like 72 DPI, which significantly reduces the file size.