-
Notifications
You must be signed in to change notification settings - Fork 618
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
feat: enable ppi setting on png cli export #8854
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Instead of ppi, can we use scale as it's the actual argument Vega uses and therefore avoids confusion?
I think they are different things? In my mind But ppi would not change the dimensions in inch of the figure, it just controls how many pixels per inch are used for the rasterization process. |
But in the end you set the scale of toCanvas so it's weird if we call the argument something else from what we already use in Vega. I don't know whether ping even has ppi. I thought it just has a resolution. See also https://graphicdesign.stackexchange.com/questions/107888/check-dpi-of-png-file. Where does 96 come from btw? |
Ah, I just did a bit more experimenting, and that was wrong, that should be 72 :) As far as I can tell, if I specify a width in vega or vega-lite, that is automatically interpreted as having a unit of pt from here. Here is how I came to that conclusion: when I save a vega-lite spec that has height of 72 * 3 and width of 72 *3, and I use autosize When I export the same figure with a scale of 2, then in both cases I get figures that are 6x6 inches. So the current interpretation of the For PNG files in general the situation is a bit trickier: by default node-canvas doesn't embed any physical size information in a PNG file. It will export a PNG file that doesn't have any physical size information, it will just be a PNG file with x times y pixels, but no additional information how much space in a physical unit a given pixel should take say on a monitor or when printed. This PR retains that behavior if the But, PNG files can also contain information how big each pixel should be in physical units. In this PR that info is embedded when one specifies the
Yes, I'm utilizing the I think the core idea of this PR is that the
https://jimpl.com/ is a convenient tool to extract that kind of information. PNG doesn't store ppi directly, it uses pixels per meter, but no piece of software that I found directly exposes that to users, they all seem to use ppi instead (including node-canvas). |
Thanks for the insightful discussion. I think I'm more convinced now but I will need to test this before merging. Also, shouldn't Vega-cli have the same option? |
Yes, that would be great! I did manage to run things on my system now, so this is no longer a completely untested PR. The way I tested this is that I created PNG files and then looked at them on that web page to see whether the info is correct.
Yes, PR I'll open a PR in a second. |
Fantastic. Thank you. I'll wait for vega/vega#3727 to land so we are in sync between Vega and Vega-Lite. |
@domoritz Any chance you could merge this, and then maybe even tag a new release with this and my other PR? I have some new stuff on the Julia side ready to go as soon as there are new versions released here. Thanks :) |
I would like to have #8857 in the next release. |
@kanitw are you making a release with the changes you sent soon? If not, let's cut a release. |
In theory this might enable saving of PNG files at higher ppi resolutions, for example create a high quality 300 ppi PNG file that still has the same height and width in physical measures. The existing
scale
argument does not allow that.I mentioned this previously at vega/vega#2269. If this PR here works I would add the same thing to
vega-cli
.I don't have a setup to test any of this :) So this is a blind PR. Sorry, I know this is not ideal...