3

Sometimes I have image files which I want to contain a certain DPI setting. Note that I mean just the DPI value, i.e. just the value in the image's metadata. I don't want to resize the actual image. So for example a higher DPI would result in a smaller size in centimeters, and the same amount of pixels.

I know I can set or change an image's DPI using ImageMagick convert with the -density parameter, but this will re-encode the image. I want to avoid that.

Is there a way, with ImageMagick or something else (e.g. ExifTool or something) to explicitly set a JPEG's DPI value without changing the actual compressed image contents itself?

Note that I'm using OS X and looking for a command line tool to do this (I want to use it in shell scripts).

1 Answer 1

12

You can do this with exiftool.

You command would be:

exiftool -XResolution=# -YResolution=# FileOrDir

Change the hashmark to the new DPI number. This command will make backups of each file, which you can avoid by adding the -overwrite_original option. Related is -ResolutionUnit which can be set to None, inches, or cm.

Also note that resolution tags may appear in multiple groups in the file, and some of them may require them to be specifically changed. Use the command in Exiftool FAQ #3 to make sure that you have changed them all.

6
  • 2
    Another option is: -jfif:Xresolution=300 -jfif:Yresolution=300 (suggested by the author of ExifTool here): u88.n24.queensu.ca/exiftool/forum/index.php?topic=2164.0)
    – Ben-Uri
    Aug 13, 2017 at 9:01
  • 4
    for 600dpi PNG files: exiftool -overwrite_original_in_place -PixelsPerUnitX=23607 -PixelsPerUnitY=23607 *.png Aug 14, 2018 at 9:32
  • 2
    @MattSephton Isn't it 600*1000/25.4 = 23622? Why 23607?
    – kol
    Jun 19, 2019 at 8:49
  • 2
    You're correct, it should be 23622. I just confirmed using Photoshop to save a 600dpi PNG. I have no recollection of this answer never mind how I came up with the other value. Jun 19, 2019 at 12:26
  • How to deal with Adobe JPEGs with APP14 marker?
    – mmj
    Jun 8, 2021 at 13:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .