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

PNG files written with wrong resolution in header #766

Closed
mhirsch opened this issue May 12, 2016 · 3 comments · Fixed by #1179
Closed

PNG files written with wrong resolution in header #766

mhirsch opened this issue May 12, 2016 · 3 comments · Fixed by #1179
Assignees
Labels

Comments

@mhirsch
Copy link

mhirsch commented May 12, 2016

Currently, a PNG encoded by node-canvas doesn't contain the correct physical size information in the header. In canvas_write_png() in PNG.h you never call png_set_pHYs() to set the physical units in the PNG header, so it defaults to 72 PPI. Most screens are 96 PPI.

Generally it would be awesome to have a way to set the physical size of the canvas from javascript. I personally would like to use this for print, where the DPI in the header changes the way the document is printed. Right now I am running an imagemagick command after the PNG is written to a file, but this is inefficient.

I could offer a patch, but of course it would be another non-standard function. I'd like to hear the thoughts of the project leaders on whether this would be something of general interest or not before I write anything.

This is potentially related to Issue #716, in that scaling the canvas may indicate that the user is looking to produce a PNG for higher PPI screens, and the PNG/SVG/PDF should probably reflect the true physical dimensions of the display device.

@LinusU
Copy link
Collaborator

LinusU commented May 12, 2016

Hmm, very interesting indeed.

Have you tried exporting PNGs from different web browser and see what they set as the PPI?

@mhirsch
Copy link
Author

mhirsch commented May 13, 2016

It seems browsers also always set the PPI to 72. There's no mechanism in the canvas spec to set the physical dimensions, so I suppose that makes sense. I don't think node-canvas should boil the ocean in making things too non-standard, which is why I'm asking for people's opinion here. It's just that I'd find it personally convenient to have such a feature! :P

@zbjornson zbjornson added the Bug label Apr 21, 2018
@zbjornson
Copy link
Collaborator

zbjornson commented Apr 21, 2018

The spec says if the file format used supports encoding resolution metadata, the resolution must be given as 96dpi (one image pixel per CSS pixel), so I think this is indeed a bug. https://html.spec.whatwg.org/multipage/canvas.html#a-serialisation-of-the-bitmap-as-a-file

In #1152/#982 I'm proposing a config object for toBuffer, so if we want to make this configurable, it would be easy to add a resolution parameter there. That would fix #716 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants