Skip to content

Commit 3a82036

Browse files
authored
Allow SVGWriter to avoid having the background element (#211)
Modify SVGWriter to be able to avoid having the background element on SVG images If you set the "background" to None or (255,255,255,0) (i.e. transparent) in the writer_options parameter when calling render then the background will not be written in the SVG (instead of having a rectangle). This is because transparent background does not seem to work in the current library (it is black)
1 parent 23e4a67 commit 3a82036

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

barcode/writer.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,15 @@ def _init(self, code):
329329
attributes = {"id": "barcode_group"}
330330
_set_attributes(group, **attributes)
331331
self._group = self._root.appendChild(group)
332-
background = self._document.createElement("rect")
333-
attributes = {
334-
"width": "100%",
335-
"height": "100%",
336-
"style": f"fill:{self.background}",
337-
}
338-
_set_attributes(background, **attributes)
339-
self._group.appendChild(background)
332+
if self.background is not None:
333+
background = self._document.createElement("rect")
334+
attributes = {
335+
"width": "100%",
336+
"height": "100%",
337+
"style": f"fill:{self.background}",
338+
}
339+
_set_attributes(background, **attributes)
340+
self._group.appendChild(background)
340341

341342
def _create_module(self, xpos, ypos, width, color):
342343
# Background rect has been provided already, so skipping "spaces"

0 commit comments

Comments
 (0)