Skip to content

Raise ValueError for SVG images with zero or missing width#112

Closed
leofernandezg wants to merge 1 commit intocdelker:masterfrom
leofernandezg:fix/svg-image-zero-width
Closed

Raise ValueError for SVG images with zero or missing width#112
leofernandezg wants to merge 1 commit intocdelker:masterfrom
leofernandezg:fix/svg-image-zero-width

Conversation

@leofernandezg
Copy link
Copy Markdown

Summary

  • Raises a clear ValueError instead of ZeroDivisionError when loading SVG images with zero or missing width attribute

Problem

parse_size_to_px(imageelm.get('width', '0')) returns 0 when width is missing (default '0'), causing s = width / imgwidth to crash with an unhelpful ZeroDivisionError.

Test results

Branch Passed Failed
master 470 0
this branch 473 0

Fixes #109

SVG images with width="0" or no width attribute caused
ZeroDivisionError at `s = width / imgwidth`. Now raises a clear
ValueError instead.

Added test/test_svg_image.py.

Fixes cdelker#109
@cdelker cdelker closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG backend image() crashes with ZeroDivisionError on SVG images with zero width

2 participants