Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow svg import without width/height attributes #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

frankbryce
Copy link

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

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 hartwork requested a review from btel November 8, 2021 13:49
@gbtami
Copy link

gbtami commented May 24, 2024

@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.

@hartwork
Copy link
Collaborator

@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.

@gbtami
Copy link

gbtami commented May 24, 2024

@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.

@hartwork
Copy link
Collaborator

@gbtami let's take this to e-mail. I sent a reply via e-mail to you just now.

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.

3 participants