svgwrite is an extension to the Python programming language which provides support for creating SVG drawings.
Questions tagged [svgwrite]
42 questions
18
votes
4 answers
How to convert SVG to PNG or JPEG in Python?
I'm using svgwrite and generating svg-files, how do I convert them to PNG or JPEG?

hkm
- 342
- 1
- 2
- 10
9
votes
1 answer
How to import an existing svg with svgwrite - Python
I need to import an existing svg picture and add elements like circle and square on it. My file is 'test.svg' so i tryed dwg = svgwrite.Drawing('test.svg') but it create a new svg file without anything.
I use the python lib svgwrite, do you have any…

Chili
- 144
- 2
- 11
8
votes
3 answers
Python Svgwrite and font styles/ sizes
I'm trying to make a SVG file connected to a web scraper.
How do I change font and text size with svgwrite? I understand that I have to define a CSS style and somehow connect that to the text object. But how is this made?
Here's the code I have so…

Peter Muungano
- 371
- 1
- 2
- 6
7
votes
1 answer
Python svgwrite module background color
I am using the svgwrite module in my Python code and I would like to set a background color. So far I have not been able to find anything. Is there a way to do it?
I was hoping for something during the initialization:
import svgwrite
canvas =…

quapka
- 2,799
- 4
- 21
- 35
5
votes
2 answers
How to implement text wrapping in svgwrite?
I'm using svgwrite in python to generate output based off my Tensorflow model to output simulated handwritten text. My current setup requires an array of strings to represent line breaks however the generated text size isn't consistent and sometimes…

TehPirate
- 154
- 1
- 12
4
votes
1 answer
Why is a generated SVG image less rich than the corresponding PNG image
To set this up, I used svgwrite library to create a sample SVG image (20 squares of length 100 at random locations on a display size of length 400)
import svgwrite
import random
random.seed(42)
dwg = svgwrite.Drawing('x.svg',…

Miraj50
- 4,257
- 1
- 21
- 34
3
votes
0 answers
How to properly rotate and translate objects in svgwrite
I would like to place a slanted rectangle with its center in a certain position, but I'm not able to properly manage the rotate and translate functions in svgwrite objects: the final position of the rectangle is not what expected (by me). For…

igmar
- 41
- 5
3
votes
3 answers
How to pass a python wordcloud element to svgwrite method to generate a svg of the wordcloud?
I am trying to generate a svg of the word_cloud being formed out of some hardcoded strings(as of now, later these strings will be dynamically generated).
Below is the Python code to generate word_cloud:
from os import path
from wordcloud import…

Shashank Salaj
- 53
- 2
- 7
3
votes
1 answer
python svgwrite can't add class attribute?
I'm trying to correct the following code:
import svgwrite
dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(dwg.circle((10, 0), 20 , fill='rgb(0,0,255)', id='rrr', class='#t'))
dwg.save()
I get the following error:
dwg.add(dwg.circle((10,…

ueke
- 33
- 1
- 4
2
votes
1 answer
How can I get svgwrite.drawing() object to reinitialize on each iteration?
I'm an artist trying my hand at some generative art, in the very early learning stages. I have some code that does what's expected on the first iteration, it makes a small svg file consisting of dozens of stacked circles, like tree rings:
import…

GreySoul
- 55
- 2
2
votes
0 answers
How to embed/use ICC color profiles using svgwrite?
I believe that there is no API method to associate/embed ICC profiles using svgwrite (correct me if I'm wrong) but is it possible to do this by e.g. manually setting parameters and so forth?
I'm a bit lost with the details about ICC and SVG in…

user272901
- 103
- 6
2
votes
1 answer
SVG embedded in SVG is of poor quality (python, svgwrite)
I am creating an svg file using python and its module svgwrite. Alongside with circles and so on (which works fine) I need to input another svg file. For that I used:
dwg = svgwrite.Drawing('test.svg', size=(size_x, size_y), …

fales
- 89
- 7
1
vote
0 answers
svgwrite rotate issues causes spiral result
Im trying to create canvas filed with triangles with random rotation and size but as soon as I try rotation everything gets out of wack. If rotation is turned off the resulting svg looks like expected
As soon as I try to get triangles to be rotated…

NccWarp9
- 486
- 1
- 5
- 19
1
vote
1 answer
Vertical alignment in SVG via svgwrite
I'm having issues with vertical alignment of texts when using the svgwrite python library.
For example, here's a simple code that generates a red-filled circle with a black text saying "Text" on top of the circle:
import svgwrite …

pelegs
- 317
- 1
- 10
1
vote
1 answer
Python svgwrite Drawing Error "not a valid value for attribute 'd' at svg-element "
I try to extract one path from a SVG in Python using minidom and then want to create a new SVG with just the first path using svgwrite.
This is my code for extracting the first path with its color:
from xml.dom import minidom
# Read svg as xml…

Hackerman
- 35
- 7