Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pHYs is metric-only #5

Open
svgeesus opened this issue Jan 19, 2021 · 4 comments
Open

pHYs is metric-only #5

svgeesus opened this issue Jan 19, 2021 · 4 comments
Labels
bug Something isn't working enhancement New feature or request needs resolved discussion

Comments

@svgeesus
Copy link
Contributor

Raised by: Dirk Schenkewitz
Originally raised: 21 Oct 2005

Dear All,

several years ago when I read the PNG specification for the first
time, I saw a little design flaw, regarding the pHYs-tag. The only
"known unit" is metre and the resolution value must be a 4-bit
integer.

Now we all know that practically all existing devices have their
resolution defined in "dpi" (dots per inch), while an inch is
25.4mm.

That means that it is impossible to specify the resolution value
of a real-world device without losing some precision, because 1m
obviously cannot be divided by 25.4mm without a remainder.

One possible solution: Specify that unit = 2 means the unit is
"inch".

I'm a bit astonished that over the years nobody seemed to notice
this, at least I did not find any hint in the archives for "dpi"
or "inch" and only one for "metre" which is about spelling.

Is it possible that nobody ever uses this tag?

Best regards
Dirk Schenkewitz

@svgeesus
Copy link
Contributor Author

Looking at 11.3.5.3 pHYs Physical pixel dimensions I suspect this comment has misunderstood the use of pHYs. It is not primarily used to specify resolution (such as "300 dpi") but rather to indicate the aspect ratio of non-square pixels.

If the pHYs chunk is not present, pixels are assumed to be square, and the physical size of each pixel is unspecified.

Also, the resolution in x and y is a four byte integer, not a four bit integer.

My feeling is that this chunk is not used very much, and when it is, it is to capture non-square pixels (for example, to archive images from some other format). However, the inability to accurately capture a physical resolution in Imperial units is well put, and possibly should be corrected or another chunk introduced to do this, if there is a need.

@svgeesus svgeesus added bug Something isn't working enhancement New feature or request labels Jan 19, 2021
@ProgramMax ProgramMax added this to the 2nd edition errata milestone Sep 16, 2021
@ProgramMax
Copy link
Collaborator

I believe you are correct that it is perhaps rarely used. And when it is, it is probably mostly used to specify non-square pixels. But that linked spec does say:

The pHYs chunk specifies the intended pixel size or aspect ratio for display of the image.

(emphasis my own)

If unit is 1, it would specify a physical resolution. And since DPI is such a common way to specify resolution, it makes sense to me to add an inch unit.
That said, US units are now all defined in terms of SI units. So I could also be convinced that adding inches isn't beneficial.

I think I am leaning toward adding an inch unit. What are your thoughts?

@ProgramMax ProgramMax removed this from the 2nd edition errata milestone Sep 16, 2021
@w3c w3c deleted a comment from Sieraleanne88 Jul 13, 2023
@svgeesus
Copy link
Contributor Author

We probably should (and add required handling for unknown unit specifiers).

In addition that section really needs a worked example, like: 72dpi

72 ÷ 25.4 × 1,000 = 2,834.64566929 = 2835
2,835 ÷ 1,000 × 25.4 = 72.009

Before doing so it would be good to run some tests to see what image display systems do with non-square pixels or with physical dimensions. PngSuite has a few tests:

For the physical pixel dimensions, the result of each decoding should be a square picture. The first (cdf) image is an example of flat (horizontal) pixels, where the pHYS chunk (x is 1 per unit, y = 4 per unit) must take care of the correction. The second is just the other way round. The last example uses the unit specifier, for 1000 pixels per meter. This should result in a picture of 3.2 cm square.

cdf - physical pixel dimensions, 8x32 flat pixels
cdh - physical pixel dimensions, 32x8 high pixels
cds - physical pixel dimensions, 8x8 square pixels
cdu - physical pixel dimensions, with unit-specifier

results show browsers ignore non-square pixels and ignore physical dimensions. Need to check against CSS and HTML specs to see correct handling there.

@svgeesus
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request needs resolved discussion
Projects
None yet
Development

No branches or pull requests

2 participants