Comments (3)
Yes, you have to give bytes to svg2svg
. Use svg = b"""…
to fix that.
from cairosvg.
Thanks for the report! It should be fixed now.
from cairosvg.
Hey @liZe
I've tried the same code with this commit cf0c406
$ pip install git+https://github.com/Kozea/CairoSVG@cf0c40677f9349ca366bbdc878f7bf0b79768161
python
Python 3.10.6 (main, Sep 11 2023, 10:27:20) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairosvg
>>> svg = """
... <svg width="30" height="42" viewBox="0 0 30 42" fill="none" xmlns="http://www.w3.org/2000/svg">
... <g id="Group">
... <g id="pin">
... <mask id="path-1-inside-1_22_336" fill="white">
... <path d="M15 0C6.71906 0 0 6.04781 0 13.5C0 25.5 15 42 15 42C15 42 30 25.5 30 13.5C30 6.04781 23.2809 0 15 0ZM15 21C13.8133 21 12.6533 20.6481 11.6666 19.9888C10.6799 19.3295 9.91085 18.3925 9.45672 17.2961C9.0026 16.1997 8.88378 14.9933 9.11529 13.8295C9.3468 12.6656 9.91824 11.5965 10.7574 10.7574C11.5965 9.91824 12.6656 9.3468 13.8295 9.11529C14.9933 8.88378 16.1997 9.0026 17.2961 9.45672C18.3925 9.91085 19.3295 10.6799 19.9888 11.6666C20.6481 12.6533 21 13.8133 21 15C20.9983 16.5908 20.3656 18.1159 19.2407 19.2407C18.1159 20.3656 16.5908 20.9983 15 21Z"/>
... </mask>
... <path d="M15 0C6.71906 0 0 6.04781 0 13.5C0 25.5 15 42 15 42C15 42 30 25.5 30 13.5C30 6.04781 23.2809 0 15 0ZM15 21C13.8133 21 12.6533 20.6481 11.6666 19.9888C10.6799 19.3295 9.91085 18.3925 9.45672 17.2961C9.0026 16.1997 8.88378 14.9933 9.11529 13.8295C9.3468 12.6656 9.91824 11.5965 10.7574 10.7574C11.5965 9.91824 12.6656 9.3468 13.8295 9.11529C14.9933 8.88378 16.1997 9.0026 17.2961 9.45672C18.3925 9.91085 19.3295 10.6799 19.9888 11.6666C20.6481 12.6533 21 13.8133 21 15C20.9983 16.5908 20.3656 18.1159 19.2407 19.2407C18.1159 20.3656 16.5908 20.9983 15 21Z" fill="#FF8B6D" stroke="#D74F31" stroke-width="4" mask="url(#path-1-inside-1_22_336)"/>
... </g>
... </g>
... </svg>
... """
>>>
>>> parsed_svg = cairosvg.svg2svg(svg)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/erwanvivien/.asdf/installs/python/3.10.6/lib/python3.10/site-packages/cairosvg/__init__.py", line 41, in svg2svg
return surface.SVGSurface.convert(
File "/Users/erwanvivien/.asdf/installs/python/3.10.6/lib/python3.10/site-packages/cairosvg/surface.py", line 129, in convert
tree = Tree(
File "/Users/erwanvivien/.asdf/installs/python/3.10.6/lib/python3.10/site-packages/cairosvg/parser.py", line 388, in __init__
if bytestring.startswith(b'\x1f\x8b'):
TypeError: startswith first arg must be str or a tuple of str, not bytes
Do you know if I made a mistake ?
from cairosvg.
Related Issues (20)
- `text` property `shape-inside` not respected HOT 1
- Convert to WebP HOT 1
- Add rlPyCairo to requirements.txt HOT 1
- OSE Error cairo-2 not found HOT 6
- Conversion of multiple files halted with error HOT 2
- SVG to PDF render improper PNG position HOT 1
- OSError: no library called "cairo-2" was found HOT 1
- RecursionError: maximum recursion depth exceeded in comparison HOT 1
- Truncating fractional height in pixels HOT 4
- svg2pdf incorrect width and height output - HOT 1
- Feature request: support style='background_color:xxxx' in the <svg> object
- Add support for blend modes
- Missing linked images and text HOT 6
- svg2png the stroke attribute causes display anomalies. HOT 1
- Fail of image path resolution in a defs/use context HOT 1
- SVG path parse error
- ValueError: could not convert string to float: 'null' HOT 1
- ValueError: could not convert string to float: '' HOT 1
- Can't convert svg to pdf HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cairosvg.