DPI metadata of PNG export should change with scale or be adjustable
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 18.8k
- Forks
- 2.8k
- Avg merge
- 16h 26m
- Merged PRs (30d)
- 21
Description
I export a figure as a png using write_image:
fig.update_layout(width=300).write_image("test_1.png", scale=1)
Opening this image in another program, the width of the image is 3.125 inches corresponding to a DPI of 96.
If I instead export an image with a different scale, e.g. 2
fig.write_image("test_2.png", scale=2)
I get a png file with a scaled pixel width (e.g. 600).
But opening the image in another program, the width in inches is also doubled to 6.25.
The ideal behavior IMO would be that the width of the image in inches is unaffected by the scale parameter or having a dpi keyword argument that sets the DPI metadata directly.
A workaround (which others might find useful) is to use Pillow to fix the DPI metadata
from PIL import Image
scale = 2
Image.open("test_2.png").save("test_2_fixed.png", dpi=(96 * scale, 96 * scale))
such that the image defaults to the same size in inches in other programs independent of the scale.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the Python write_image export path and compare the PNG metadata produced with scale=1 and scale=2. Verify the resulting physical dimensions in another image program; done means scaling pixels no longer changes the physical size, or a dpi option provides the requested metadata control.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100