svg_utils
svg_utils copied to clipboard
Allow svg import without width/height attributes
This is possible in an .svg file, as indicated by this stackexchange post [1]. I also have created them and they render just fine. Further, your code seems to already support having a None value for self._height and self._width so it seems that not much has to change.
Without this check, the code raises an exception.
...
File "/home/jonnyjack7/.local/lib/python3.9/site-packages/svgutils/compose.py", line 122, in __init__
if svg.width.endswith("%"):
AttributeError: 'NoneType' object has no attribute 'endswith'
[1] https://graphicdesign.stackexchange.com/a/71574
@hartwork I run into this exact error today. I try to generalize https://github.com/RoepStoep/lidraughts-boardimage to support chess variants playable on pychess.org and it has lots of piece images with no width/height svg attribs. It would be nice to have a new version with this PR merged. Maybe @btel is busy with real life stuff in past 3 years.
@gbtami I agree that svg_utils is not getting the love it needs. I see no current use of svg_utils in https://github.com/RoepStoep/lidraughts-boardimage — am I missing something?
PS: While I seem to be able to close pull requests here, I have no write access to https://pypi.org/project/svgutils/ , if you're wondering.
@hartwork I find the idea to use svg_utils to load and scale piece images in your https://github.com/hartwork/xiangqi-setup :)
Btw I faced another minor issue:
# This can read "viewBox" but can't do scale()
svg = svgutils.transform.fromfile(orig_file)
# This can't read "viewBox" but can do scale()
svg = svgutils.compose.SVG(orig_file)
Maybe I should create a github fork of this repo and use it until this upstream repo will be active again. Idk.
@gbtami let's take this to e-mail. I sent a reply via e-mail to you just now.