Importing a PNG image with unittype field undefined fails

Bug #1302987 reported by jazzynico on 2014-04-05
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Medium
jazzynico

Bug Description

The attached PNG image is imported with an incorrect resolution, due to a missing unit type field.

The command "identify -verbose IMG_5466.png" returns:

Image: IMG_5466.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 1136x640+0+0
  Resolution: 72x72
  Print size: 15.7778x8.88889
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit

But the ImageMagick fallback in the Inkscape import code gives:

x_: 182.88
y_: 182.88

Note that the x_ and y_ values are due to the incorrect guess by our code that the unit type is in pixels by centimeter (182.88 = 72 * 2.54). Also note that 72 is the default resolution used by ImageMagick (independently of our code) when no unit type is set.

What should we do with such images?
1. Accept the default 72dpi value (and fix the invalid conversion on our side).
2. Mark the resolution as invalid and use the default Inkscape import resolution instead.

jazzynico (jazzynico) wrote :
Changed in inkscape:
assignee: nobody → jazzynico (jazzynico)
su_v (suv-lp) wrote :

(reproduced with r13266 and ImageMagick 6.8.8-10 on OS X 10.7.5)

Changed in inkscape:
status: New → Triaged
Alvin Penner (apenner) wrote :

I would vote for option 1 : >> 1. Accept the default 72dpi

This is equivalent to assuming that the Print Size has been specified in inches, which seems like a reasonable default.

jazzynico (jazzynico) wrote :

ImageMagick provides xResolution() and yResolution() functions that seem to give the correct resolution with no need to convert locally (see http://www.imagemagick.org/api/Magick++/classMagick_1_1Image.html#a97fb513d13fbb1689ed5e51d8cf0b588).

Patch in progress.

Changed in inkscape:
status: Triaged → In Progress
jazzynico (jazzynico) wrote :

And I still can't understand why I used the density() function first...

Patch tested on Windows XP, Inkscape trunk revision 13273, with the attached PNG and some other PNG and JPG files (by forcing them to use the IM fallback).

su_v (suv-lp) wrote :

Patch tested "successfully" [*] with r13274 on OS X 10.7.5, ImageMagick 6.8.8-10.

[*] Due to the lack of assorted test images (with known fail/success status), I tested random bitmap images in the 'Download' folder: ImageMagick doesn't seem to return 'ok' x/yResolution values for PNG images (at least I didn't encounter one), but I saw the fallback getting used for a TIF and a JPEG image (verified with a modified version of the patch (attached) which outputs the resolution to the console (thx to JazzyNico for the initial version of the debug macro)).

[ Unrelated observation: readpng() seems to return rather random values if the file does not provide the required information (can vary for the same file in the current session if another bitmap was imported in-between repeated runs, and seems to vary across sessions.... ]

jazzynico (jazzynico) wrote :

Fix committed revision 13279.

Thanks for your tests, ~suv!

A patch dedicated to debug code is in progress.

Changed in inkscape:
status: In Progress → Fix Committed
jazzynico (jazzynico) on 2015-02-14
Changed in inkscape:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers