Closed roberto-arista closed 1 year ago
Does image() support SVG to begin with?
I was able to draw some svgs on a canvas, so I assumed drawbot supports them
Ah, it doesn't work on 10.15 for example. It's mostly an OS support thing.
That said the imageSize()
implementation goes through some hoops to support PDF, (animated) GIF and "others". Maybe it needs some SVG handling code.
A lots goes wrong while drawing svg as images...
but we could get the size from the nsimage object, we just have to flag _hasPixels = True
with the ext .svg
here
my workaround for now is this:
import xml.etree.ElementTree as ET
tree = ET.parse(imagePath)
_, _, imageWidth, imageHeight = [float(i) for i in tree.getroot().attrib["viewBox"].split()]
I understand that svg support as input format might be complicated and unreliable. I ended up converting the svg files in pdf with cairosvg and it worked fine. I'll open a pull request to add to the docs which formats are supported by the image proporties functions and the ImageObject.
I can't get the correct width and height from a svg file with
imageSize()
. Even though the svg has aviewBox
attribute with positive width and height,imageSize()
returns(0, 0)