Created
July 6, 2016 14:00
-
-
Save fernandoc1/40a8f88236e6d4dbaf498592c66e996e to your computer and use it in GitHub Desktop.
Creating colorful Google Markers with python for using in CGI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
from xml.dom import minidom | |
import os | |
import sys | |
import cairo | |
import rsvg | |
markerDocument = minidom.parse('marker.svg') | |
svg = markerDocument.getElementsByTagName("svg")[0] | |
imgHeight = float(svg.attributes['height'].value) | |
imgWidth = float(svg.attributes['width'].value) | |
color = os.environ['QUERY_STRING'] | |
if (len(color) != 6): | |
color = "00FF00" | |
style = "clip-rule:evenodd;fill-rule:evenodd;stroke:#000000;stroke-width:0.58006144;stroke-miterlimit:10;fill-opacity:1;" | |
style += "fill:#"+color | |
markerPath = markerDocument.getElementsByTagName("path")[0] | |
markerPath.setAttribute("style", style) | |
svgXmlData = markerDocument.toxml() | |
img = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(imgWidth), int(imgHeight)) | |
ctx = cairo.Context(img) | |
handle = rsvg.Handle(None, svgXmlData) | |
handle.render_cairo(ctx) | |
print "Content-type: image/png\n" | |
img.write_to_png(sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment