convert will result in file with 1x1 dpi

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Dee
Posts: 3
Joined: 2014-01-28T13:01:44-07:00
Authentication code: 6789

convert will result in file with 1x1 dpi

Post by Dee »

Hello,

currently I'm using Ubuntu 12.04 LTS with version:

Code: Select all

$ identify -version
Version: ImageMagick 6.6.9-7 2012-08-17 Q16 http://www.imagemagick.org
If I use identify to extract information from some image (Download) the result is:

Code: Select all

$ identify -verbose winprog4-Darktable.png
Image: winprog4-Darktable.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 1216x651+0+0
  Resolution: 72x72
  Print size: 16.8889x9.04167
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB
If I convert this image to JPG I get:

Code: Select all

$ convert winprog4-Darktable.png winprog4-Darktable.jpg
$ identify -verbose winprog4-Darktable.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 1216x651+0+0
  Resolution: 72x72
  Print size: 16.8889x9.04167
  Units: PixelsPerInch
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB
So, the Resolution, Print size and Units are set after the conversion.

With a newer version of ImageMagick (e.g. 6.8.8-2 or -3) I get:

Code: Select all

$ identify -verbose winprog4-Darktable.png
Image: winprog4-Darktable.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 1216x651+0+0
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB

Code: Select all

$ convert winprog4-Darktable.png winprog4-Darktable.jpg
$ identify -verbose winprog4-Darktable.jpg
Image: winprog4-Darktable.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 1216x651+0+0
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
As you see, the Units are still Undefined and Resolution and Print size are missing. They are already missing in the original PNG.

This conversion leads to some serious errors. If I open the images in GIMP it says:

Code: Select all

Original PNG:
Print size: 428,98 × 229,66 millimeters
Resolution: 72x72 ppi

Converted JPG (ImageMagick 6.6.9-7):
Print size: 428.98 × 229.66 millimeters
Resolution: 72x72 ppi

Converted JPG (ImageMagick 6.8.8-3):
Print size: 30886.40 × 16535.40 millimeters
Resolution: 1 × 1 ppi
Other imaging tools will also "set" the Resolution to 1x1 DPI. The image is so huge that I cannot embed in some other documents (e.g. LaTeX).

My questions: What has changed between these two version? Why does identify do not print all informations anymore? Was the change intentional or is it a bug? Can I help to fix it somehow?

Best regards
Dee
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert will result in file with 1x1 dpi

Post by fmw42 »

If the units are undefined, then IM says I do not know what units it is, so just keep it unknown. It is bad form to assume it is pixels per inch. You can probably convert the image with -units pixelsperinch and force it to be set to those units. Give that a try and let us know what happens.

Also note that PNG does not support pixels per inch, only pixels per centimeter, so the 72x72 dpi in your input PNG is likely bogus as well. So I would have to say that your input PNG image was not created correctly, if it reports 72x72 and units=undefined.
Dee
Posts: 3
Joined: 2014-01-28T13:01:44-07:00
Authentication code: 6789

Re: convert will result in file with 1x1 dpi

Post by Dee »

So I would have to say that your input PNG image was not created correctly, if it reports 72x72 and units=undefined.
This is a simple screenshot done by hitting the Alt-Print-Key on the keyboard. identify 6.6.9-7 always reports 72x72 dpi.
You can probably convert the image with -units pixelsperinch and force it to be set to those units. Give that a try and let us know what happens.
That does not change anything. The converted JPG still has 1x1 dpi.

But this works:

Code: Select all

$ convert -units PixelsPerInch -density 72x72 winprog4-Darktable.png winprog4-Darktable.jpg
$ identify -verbose winprog4-Darktable.jpg
Image: winprog4-Darktable.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 1216x651+0+0
  Resolution: 72x72
  Print size: 16.8889x9.04167
  Units: PixelsPerInch
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
So I suppose convert in version 6.6.9-7 uses the default parameters PixelsPerInch and resolution 72x72. This seems corrrect, if you take a look at the manual: http://www.imagemagick.org/script/comma ... hp#density: "The default unit of measure is in dots per inch (DPI). [...] The default resolution is 72 dots per inch, [...]"

So the question is still open: Why has the default behaviour changed? Was that intentional? Or is it a bug?

Best regards
Dee
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert will result in file with 1x1 dpi

Post by fmw42 »

I believe it was intentional and my reason above still stands. If the units are unknown, it is better to say so than to express them as 1x1 dpi.

Your windows command to take a screen snap is not creating a proper set of density and especially units. It seems to be "stupid" about it.

If you believe that the units are really pixelsperinch, then convert the input image to set the units.

convert image -units pixelsperinch newimage

or write over the input. But if the input is jpg, then you will lose a little quality as IM will decode and then re-encode the compression.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert will result in file with 1x1 dpi

Post by fmw42 »

If you want to reset the dpi and/or units without affecting the data (such as jpeg compression), then use EXIFTOOL to write into those fields meta data. You can check to see what dpi and units are being reported by EXIFTOOL to see what it say when IM reports density=undefined.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert will result in file with 1x1 dpi

Post by snibgo »

In Windows, Alt-PrtSc just copies the image of a window to the clipboard. I don't know what metadata it copies.

We can use IM to make a png from the clipboard:

Code: Select all

convert clipboard: x.png
The resulting png has no density; neither a number nor units (according to exiftool). We can:

Code: Select all

convert clipboard: -density 72 -units PixelsPerInch x.png
There may be a facility in Windows to find the actual DPI, if you want.
snibgo's IM pages: im.snibgo.com
Dee
Posts: 3
Joined: 2014-01-28T13:01:44-07:00
Authentication code: 6789

Re: convert will result in file with 1x1 dpi

Post by Dee »

@snibgo: The screenshots are from an external source. So I must live with what I get.
If the units are unknown, it is better to say so than to express them as 1x1 dpi.
Yes, you might be right but the default behaviour (as mentioned in the manual) has changed.

I have now changed my conversion script so that If I convert from PNG to JPG it uses the old default behaviour of convert with "-units PixelsPerInch -density 72x72". In all other cases I do not change anything and just convert the formats.

Best regards
Dee
Post Reply