Exception "The SVG size is undefined" raised using svg2png
- Dominant language
- Python
- Stars
- 951
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
Converting the following SVG file (see code bellow) into a PNG caused an exception to be raised:
```
Traceback (most recent call last):
File "/Volumes/Test/main.py", line 12, in
cairosvg.svg2png(url=URL, write_to=OUTPUT_PATH)
File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/__init__.py", line 55, in svg2png
return surface.PNGSurface.convert(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 133, in convert
instance = cls(
^^^^
File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 225, in __init__
self.draw(tree)
File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 472, in draw
self.draw(child)
File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 472, in draw
self.draw(child)
File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 480, in draw
paint_mask(self, node, mask, opacity)
File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/defs.py", line 145, in paint_mask
mask_surface = SVGSurface(mask_node, None, surface.dpi, surface)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Volumes/Test/venv/lib/python3.12/site-packages/cairosvg/surface.py", line 209, in __init__
raise ValueError('The SVG size is undefined')
ValueError: The SVG size is undefined
```
Here is the code to reproduce:
```python
import cairosvg
URL = "https://upload.wikimedia.org/wikipedia/commons/3/32/Saltwater_Limpet_Diagram-en.svg"
OUTPUT_PATH = "output.png"
cairosvg.svg2png(url=URL, write_to=OUTPUT_PATH)
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the provided Python script and SVG URL, reproducing the failure through cairosvg.svg2png. Trace the reported path in cairosvg/surface.py around SVGSurface and mask handling, then add a regression test for this input; done means the SVG converts to PNG without the reported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100