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).


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 -overwrite_original. Related is -ResolutionUnit which can be set to None, inches, or cm.

  • 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 '17 at 9:01
  • 2
    for 600dpi PNG files: exiftool -overwrite_original_in_place -PixelsPerUnitX=23607 -PixelsPerUnitY=23607 *.png – Matt Sephton Aug 14 '18 at 9:32
  • 1
    @MattSephton Isn't it 600*1000/25.4 = 23622? Why 23607? – kol Jun 19 '19 at 8:49
  • 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. – Matt Sephton Jun 19 '19 at 12:26
  • How to deal with Adobe JPEGs with APP14 marker? – mmj Jun 8 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.