Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
style_detail[ind] = "font-family:" + font[row]
style_detail = ';'.join(style_detail)
text_nodes = path.getchildren()
path.set("style", style_detail)
for t in text_nodes:
text_style_detail = t.get("style")
if text_style_detail is not None:
text_style_detail = text_style_detail.split(";")
text_style_detail[-1] = "font-family:" + font[row]
text_style_detail = ";".join(text_style_detail)
t.set("style", text_style_detail)
else:
t.set("style", "font-family:" + font[row])
etree.ElementTree(element).write(filename, pretty_print=True)
print("Font Family Saved!")
for t in text_nodes:
text_style_detail = t.get("style")
if text_style_detail is not None:
text_style_detail = text_style_detail.split(";")
for ind, i in enumerate(text_style_detail):
if i.split(':')[0] == 'fill':
text_style_detail[ind] = "fill:" + str(logo_fill)
text_style_detail = ";".join(text_style_detail)
t.set("style", text_style_detail)
else:
t.set("style", "fill:" + str(logo_fill))
path.set("style", style_detail)
etree.ElementTree(element).write(filename, pretty_print=True)
print("Text Fill saved!")
filename = filename.rsplit(".", 1)[0] + '.svg'
filename = os.path.join(SVGS_FOLDER, filename)
tree = parse(open(filename, 'r'))
element = tree.getroot()
# changing style using XPath.
path = element.xpath('//*[@id="rect4504"]')[0]
style_detail = path.get("style")
style_detail = style_detail.split(";")
style_detail[0] = "opacity:" + str(opacity)
style_detail[1] = "fill:" + str(fill)
style_detail = ';'.join(style_detail)
path.set("style", style_detail)
# changing text using XPath.
path = element.xpath('//*[@id="tspan932"]')[0]
# Saving in the original XML tree
etree.ElementTree(element).write(filename, pretty_print=True)
print("done")
svg2png(url=filename, write_to=UPLOAD_FOLDER + '/' + png_filename)
print("Image Saved")
filename = os.path.join(self.APP_ROOT, 'svg', 'user_defined.svg')
tree = parse(open(filename, 'r'))
element = tree.getroot()
# changing style using XPath.
path = element.xpath('//*[@id="rect4504"]')[0]
style_detail = path.get("style")
style_detail = style_detail.split(";")
style_detail[0] = "opacity:" + str(opacity)
style_detail[1] = "fill:" + str(fill)
style_detail = ';'.join(style_detail)
path.set("style", style_detail)
# changing text using XPath.
path = element.xpath('//*[@id="tspan932"]')[0]
# Saving in the original XML tree
etree.ElementTree(element).write(filename, pretty_print=True)
print("done")
png_name = os.path.join(self.APP_ROOT, 'static', 'uploads', 'image', str(uuid.uuid4())) + ".png"
svg2png(url=filename, write_to=png_name)
return png_name
text_nodes = path.getchildren()
path.set("style", style_detail)
for t in text_nodes:
text_style_detail = t.get("style")
if text_style_detail is not None:
text_style_detail = text_style_detail.split(";")
for ind, i in enumerate(text_style_detail):
if i.split(':')[0] == 'font-size':
text_style_detail[ind] = "font-size:" + str(font_size[row]) + 'px'
text_style_detail = ";".join(text_style_detail)
t.set("style", text_style_detail)
else:
t.set("style", "font-size:" + str(font_size[row]) + 'px')
etree.ElementTree(element).write(filename, pretty_print=True)
print("Font Size Saved!")
def remove_extra(badge_page, offset):
tree = etree.parse(open(badge_page, 'r'))
root = tree.getroot()
children = root.findall('.//{http://www.w3.org/2000/svg}g')
for i in range(offset, len(children)):
children[i].getparent().remove(children[i])
etree.ElementTree(root).write(badge_page, pretty_print=True)