deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
324 stars 79 forks source link

Unable to convert svg to png #346

Closed jamessappy closed 2 years ago

jamessappy commented 2 years ago

Hi,

I'm trying to convert a svg file to png. I've used the following code:

      _from svglib.svglib import svg2rlg
      from reportlab.graphics import renderPM_

      _drawing = svg2rlg(svg_path)
      renderPM.drawToFile(drawing, png_path, fmt= 'PNG')_

I receive the following error message:

      _AttributeError: 'lxml.etree._Element' object has no attribute 'ancestors'. Did you mean: 'iterancestors'?_

I'm not exactly sure what my issue here is, thought maybe it was my version but I've updated python as well as the svglib and reportlab libraries and still haven't had any luck.

Thanks!

github-actions[bot] commented 2 years ago

Thank you for raising your first issue! Your help to improve svglib is much appreciated!

claudep commented 2 years ago

I think a full error traceback could help spotting the issue more precisely.

jamessappy commented 2 years ago

Are you referencing this?

_Traceback (most recent call last): File "c:\Users\James\Desktop\HeadlessConvertToPNG.py", line 8, in drawing = svg2rlg(svg_path) File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\svglib\svglib.py", line 1468, in svg2rlg drawing = svgRenderer.render(svg_root) File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\svglib\svglib.py", line 553, in render main_group = self.renderSvg(node, outermost=True) File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\svglib\svglib.py", line 834, in renderSvg self.renderNode(child, group) File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\svglib\svglib.py", line 584, in renderNode item = self.renderG(n, clipping=clipping) File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\svglib\svglib.py", line 868, in renderG matches = rules.match(self) File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\cssselect2__init.py", line 93, in match self.add_relevant_selectors( File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\cssselect2\init.py", line 120, in add_relevant_selectors if test(element): File "", line 1, in File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\svglib\svglib.py", line 503, in getattr__ return getattr(self.object, name)AttributeError: 'lxml.etree.Element' object has no attribute 'ancestors'. Did you mean: 'iterancestors'?PS C:\Users\James\Desktop>

claudep commented 2 years ago

Thanks, yes, it helps. Would it be possible to also have the SVG file that triggers this error?

claudep commented 2 years ago

Oh, and the version of svglib you are using, please.

jamessappy commented 2 years ago

I am using version 1.3.0 of the svlib library. I've also attached the .svg file that I'm trying to convert.

NewSunPath

claudep commented 2 years ago

Thanks, I was able to reproduce the issue, a first step to resolution :-)