DPI info ImageMagick vs Photoshop

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply

DPI info ImageMagick vs Photoshop

Post by benmie »


I am a IM newbie, but I hope I can explain my problem :)

I have an image 1000x1000 and 300dpi, it has been created in photoshop.
If I run this command line:
convert Testfile1000x1000.jpg -depth 8 -density 72 Testfile1000x1000ver1.jpg and afterwards this
identify -format %x Testfile1000x1000_72ver1.jpg I get this result
72 PixelsPerInch

When I open this image in Photoshop it still says 300dpi.

I don't understand :)

Hope someone can clarify things or explain if I am doing something wrong :)
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: DPI info ImageMagick vs Photoshop

Post by Drarakel »

Note that Photoshop stores and obtains image resolution from a proprietary embedded profile. If this profile is not stripped from the image, then Photoshop will continue to treat the image using its former resolution, ignoring the image resolution specified in the standard file header.
From here: http://www.imagemagick.org/script/comma ... hp#density
See also here: http://www.imagemagick.org/Usage/formats/#jpg_write

You should strip all of the metadata (with "-strip") or at least the Photoshop profile if you want to update the density value with ImageMagick (which updates 'only' the EXIF and JFIF header values):
convert -units PixelsPerInch Testfile1000x1000.jpg +profile "8bim" -density 72 Testfile1000x1000ver1.jpg

But if you want to change only metadata, a better solution is to use ExifTool:
Here, you can change these values without recompressing the image (so it's lossless). A command that usually updates the density in all places:
exiftool -ResolutionUnit=inches -DisplayedUnitsX=inches -DisplayedUnitsY=inches -XResolution=72 -YResolution=72 -overwrite_original <file>

Re: DPI info ImageMagick vs Photoshop

Post by vepxistqaosani »

I'm having a similar problem.

exiftool (and irfanview and photoshop) and identify give different results for the same image:

identify :
Geometry: 1743x1722+0+0
Resolution: 499x499
Print size: 3.49299x3.4509
Units: PixelsPerInch

Image Width : 1743
Image Height : 1722
X Resolution : 350
Y Resolution : 350
Exif Image Width : 1743
Exif Image Height : 1722
Image Size : 1743x1722

So where is identify getting a resolution of 499?

Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: DPI info ImageMagick vs Photoshop

Post by snibgo »

If you post a URL of the file, someone might take a look.
snibgo's IM pages: im.snibgo.com
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: DPI info ImageMagick vs Photoshop

Post by Drarakel »

Probably there are different values in different profiles. But a link to the file would be better, yes.
You could also post the complete output of exiftool (for example with "exiftool -s -ee -g").

Re: DPI info ImageMagick vs Photoshop

Post by vepxistqaosani »

Thanks! I now know where the problem is coming from. In the exiftool results below, the XMP section shows a different resolution from the Photoshop and EXIF sections.

ImageMagick is taking the size from the EXIF section and the resolution from the XMP section. It ignores the EXIF resolution and the XMP size. But why?

exiftool.pl -s -ee -g Square.tif
---- ExifTool ----
ExifToolVersion : 8.25
---- File ----
FileName : Square.tif
Directory : .
FileSize : 11 MB
FileModifyDate : 2010:07:14 09:33:44-04:00
FilePermissions : rw-rw-rw-
FileType : TIFF
MIMEType : image/tiff
ExifByteOrder : Big-endian (Motorola, MM)
CurrentIPTCDigest : 8cd1cec100db56eee4951930207e3206
---- EXIF ----
SubfileType : Full-resolution Image
ImageWidth : 1743
ImageHeight : 1722
BitsPerSample : 8 8 8 8
Compression : Uncompressed
PhotometricInterpretation : CMYK
StripOffsets : 8452
SamplesPerPixel : 4
RowsPerStrip : 1722
StripByteCounts : 12005784
XResolution : 350
YResolution : 350
PlanarConfiguration : Chunky
ResolutionUnit : inches
Software : Adobe Photoshop 7.0
ModifyDate : 2007:10:10 08:33:09
ColorSpace : Uncalibrated
ExifImageWidth : 1743
ExifImageHeight : 1722
---- XMP ----
XMPToolkit : XMP toolkit 2.8.2-33, framework 1.5
About : uuid:c2fd33af-789d-11dc-ae1e-c2292eb8aea8
ColorSpace : sRGB
ExifImageWidth : 2999
ExifImageHeight : 2963
History :
Orientation : Horizontal (normal)
XResolution : 499
YResolution : 499
ResolutionUnit : inches
CreateDate : 2007:03:15 15:22:00-05:00
ModifyDate : 2007:03:15 15:22:00-05:00
MetadataDate : 2007:03:15 15:22:00-05:00
CreatorTool : Adobe Photoshop CS Macintosh
DerivedFromInstanceID : uuid:baeee068-b4d8-11d9-b25c-d7897bb9fed7
DerivedFromDocumentID : adobe:docid:photoshop:baeee062-b4d8-11d9-b25c-d7897bb9fed7
DocumentID : adobe:docid:photoshop:f22c6d9b-d498-11db-877a-e7850a3156db
Format : image/jpeg
---- IPTC ----
ApplicationRecordVersion : 2
ApplicationRecordVersion : 2
---- Photoshop ----
IPTCDigest : 460cf28926b856dab09c01a1b0a79077
XResolution : 350
DisplayedUnitsX : inches
YResolution : 350
DisplayedUnitsY : inches
GlobalAngle : 120
GlobalAltitude : 30
CopyrightFlag : False
---- Composite ----
ImageSize : 1743x1722
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: DPI info ImageMagick vs Photoshop

Post by Drarakel »

If you think that the EXIF profile always has the correct density value and that there could be false values in the XMP or Photoshop profile, then you probably should strip the profiles before you're doing any conversions. But not with ImageMagick - because at the time you use "-strip", IM has already read the (potentially false) density value. :)
For JPGs, it's probably not necessary. (I think, the density value is always searched within the EXIF and JFIF header sections first.)
For TIF files, you could again use ExifTool. To play safe, you could delete the mentioned values with "exiftool -Photoshop:All= -XMP:XResolution= -XMP:YResolution= -XMP:ResolutionUnit= -overwrite_original file.tif"

Or, you could try to update the values - for example with:
exiftool "-XResolution>XResolution" "-YResolution>YResolution" "-ResolutionUnit>ResolutionUnit" "-ResolutionUnit>DisplayedUnitsX" "-ResolutionUnit>DisplayedUnitsY" -overwrite_original file.tif"
After that, everywhere's the same density (except EXIF thumbnails). And ExifTool should take the values in TIF from EXIF first (if they exist there). But I don't know if this last method works for all TIF files...
User avatar
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: DPI info ImageMagick vs Photoshop

Post by anthony »

If you tell photoshop to save the image "For Web" then I believe it sets the DPI values correctly in the other parts of the image file format.

However i do not have confirmation of this. I don't use photoshop!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages

Re: DPI info ImageMagick vs Photoshop

Post by vepxistqaosani »

I had been using version 6.5.9; upgrading to 6.6.3 solved my problem.

I suppose there still could be TIFFs out there that will confuse IM, but v.6.6.3 reads all my 'bad' examples correctly.

Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: DPI info ImageMagick vs Photoshop

Post by Drarakel »

If someone's still interested in the situations in which the current ImageMagick versions could get 'confused' about the density values in the different profiles.. I had made some tests back then for JPG and TIFF. I think it's as follows:

With JPG files:

The density values are taken from these places (sorted by priority):
EXIF -> JFIF -> EXIF thumbnail (!) -> Photoshop -> default value
(That means: The density is searched first in the EXIF profile, then in the JFIF header, and so on. And the values from e.g. the '8BIM' Photoshop profile are only taken, if there are no values in the other listed profiles.)

The units value (PixelsPerInch/PixelsPerCentimeter/Undefined) is taken from here:
XMP -> EXIF -> EXIF thumbnail -> JFIF -> default

The default in JPG is 72x72 - unit 'undefined'.
It should be noted that with JPGs, ImageMagick reads the horizontal density, the vertical density and the units value completely independently. That means that - in an extreme case - the horizontal density could be from the EXIF thumbnail (IFD1), the vertical density is the default value and the units value comes from the XMP profile, for example.

Oh, and if one of the density values is 0, the "Resolution" (and "Print size") doesn't get displayed in the 'identify -verbose' info. But it can still be retrieved with 'identify -format "%x %y"'.

With TIFF files:

density values:
Photoshop -> EXIF -> default

units value:
XMP -> EXIF -> default

The default for TIFF is 72x72 PixelsPerInch.
And here, IM reads the horizontal and vertical density values only 'as pair'. Example: There's no Photoshop profile and ImageMagick reads the horizontal density from the EXIF profile. Now if there's no EXIF tag for the vertical density (unlikely case), IM sets this value to 0 (and again doesn't display it in the verbose info). So, that's a bit different to the JPG handling.

Warning: I can't exclude the possibility that some things are missing or that there are other factors that influence the handling of the density values. (But, well, in my tests it was always like that in the current IM versions.)

About the writing of these values:
When one updates the properties of a JPG file with ImageMagick, the values can only get written into JFIF and EXIF (even EXIF thumbnail is 'updated'!). EXIF only if such a profile is already existing. With TIFF, I think it's only EXIF. So, that means that after updating the values with ImageMagick, it's possible that IM itself still displays different values (for example: the units value from the XMP profile). But it's not a big issue - as long as one knows about these things.
Post Reply