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

Vague error when no height or width tag is in the svg #125

Open
oskeith opened this issue Jul 14, 2023 · 1 comment
Open

Vague error when no height or width tag is in the svg #125

oskeith opened this issue Jul 14, 2023 · 1 comment

Comments

@oskeith
Copy link

oskeith commented Jul 14, 2023

When exporting an svg from Adobe Illustrator, by default, "responsive" is ticked and no width or height tag is set. In that case, a vague error is thrown. I think it would really help a new user if there was a check and an appropriate message if the svg has no width or height tag.

import svgutils.compose as sc
sc.SVG(os.path.join(file_directory, 'face_border resp.svg'))

File "[main]", line 55, in
sc.SVG(os.path.join(file_directory, 'face_border resp.svg'))
File "C:\Users\keith\miniconda3\lib\site-packages\svgutils\compose.py", line 122, in init
if svg.width.endswith("%"):
AttributeError: 'NoneType' object has no attribute 'endswith'

Thanks!

@qubodup
Copy link

qubodup commented Aug 11, 2023

Same with some SVGs I have to deal with, even after editing manually in Inkscape.

Related issue: astraw/svg_stack#8 which includes sample file and fix

Sample affected file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg
   version="1.1"
   id="Capa_1"
   x="0px"
   y="0px"
   viewBox="0 0 512.107 512.107"
   style="enable-background:new 0 0 512.107 512.107;"
   xml:space="preserve"
   sodipodi:docname="test.svg"
   inkscape:version="1.2.2 (732a01da63, 2022-12-09)"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg"><defs
   id="defs85" /><sodipodi:namedview
   id="namedview83"
   pagecolor="#505050"
   bordercolor="#eeeeee"
   borderopacity="1"
   inkscape:showpageshadow="0"
   inkscape:pageopacity="0"
   inkscape:pagecheckerboard="0"
   inkscape:deskcolor="#505050"
   showgrid="false"
   inkscape:zoom="0.4608412"
   inkscape:cx="-1332.3462"
   inkscape:cy="451.34853"
   inkscape:current-layer="Capa_1" />
<rect
   style="fill:#efe3cd;stroke-width:11.3386;stroke-linecap:round;stroke-linejoin:round;stop-color:#000000"
   id="rect287"
   width="160.57593"
   height="128.02675"
   x="99.817467"
   y="141.04642" /></svg>

zip of file for easier download maybe:
test.zip

Resizing canvas of the svg in Inkscape fixes this by the way.

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

No branches or pull requests

2 participants