vega / vl-convert

Utilities for converting Vega-Lite specs from the command line and Python
BSD 3-Clause "New" or "Revised" License
89 stars 9 forks source link

Add ppi argument #86

Closed jonmmease closed 10 months ago

jonmmease commented 1 year ago

Closes https://github.com/vega/vl-convert/issues/85, relies on https://github.com/image-rs/image-png/pull/403 which was released in png 0.17.10.

jonmmease commented 1 year ago

https://github.com/image-rs/image-png/pull/403 was merged, so now we just need to wait for a release of image-png.

Also, adding the pixel dimensions metadata broke the CLI test because they are still doing exact binary comparison. So we need to either regenerate the baseline images, or use DSSIM for approximate comparison like we do with the vl-convert-rs tests.

jonmmease commented 1 year ago

@joelostblom, development wheel are available for this PR at https://github.com/vega/vl-convert/actions/runs/5581857544 (just download and unzip the wheels.zip artifact).

With these wheels, you can add a ppi kwarg to the vlc.vegalite_to_png and vlc.vega_to_png functions. I followed https://github.com/vega/vega-lite/pull/8854 and set things up to increase the scale internally as the ppi increases, so you can leave scale at 1 and increase PPI and the resulting image in PDF export should be the same size but sharper.

When you have a chance, let me know how this works for you!

joelostblom commented 1 year ago

Thanks so much for the quick PR! This is working for me and I am able to adjust both the size and ppi of the charts independently after adding a ppi argument to the the function you created previosuly. As expected, I am getting a constant size at different sharpness in JupyterBooks pdflatex output (to the left in the image below) whilst in JupyterLab, the size of the figure changes instead:

image

jonmmease commented 12 months ago

Thanks for trying it out @joelostblom, glad it's working as expected! The PR in image-png was merged and the next release should be in a couple of weeks, so I'll put this PR on hold until that point.

joelostblom commented 10 months ago

Just a heads up that I noticed that there was a new release made for image-png last week (or at least there is a new tag at https://github.com/image-rs/image-png/tags).

jonmmease commented 10 months ago

Oh, awesome. I had missed that go by. I'll get this PR updated soon