def color_translate_svg(filename, file_to_save = None):
		"""
		Take a filename to an SVG image and convert it to grayscale
		if file_to_save is None, it will overwrite the file!
		replace should be an instance of the Replace class
		"""
		print "Coloring: " + os.path.basename(filename) + " -> " + (file_to_save and file_to_save or os.path.basename(filename))

		# open and parse the file
		svg = SVGFile(filename)

		xml_file.translate(svg)

		# save the file
		svg.save(file_to_save)
def convert_svg_to_grayscale(filename, file_to_save = None):
	"""
	Take a filename to an SVG image and convert it to grayscale
	if file_to_save is None, it will overwrite the file!
	"""
	print "Grayscaling: " + basename(filename) + " -> " + (file_to_save and file_to_save or basename(filename))

	# open and parse the file
	svg = SVGFile(filename)

	# grayscale the image
	grayscale(svg)

	# save the file
	svg.save(file_to_save)
def test_create_svg():
	"""
	Create an SVG file with some elements
	"""
	print blue("Starting SVG creation test")
	# create our SVG
	print "Creating blank SVG"
	test = SVGFile()

	# add a colored gradient
	print "Adding colored gradient"
	a = test.add_linear_gradient("my_gradient")
	print "Adding gradient stops"
	a.add_stop(color="#ff0000ff", offset="0")
	a.add_stop(color="#00ffffff", offset="1")

	# add a positioned gradient with an xlink for the color
	print "Adding positioned gradient"
	test.add_linear_gradient("full_diag", startx=0, starty=0, stopx=1, stopy=1, xlink="#my_gradient")

	# add a rectangle
	print "Adding rectangle"
	test.add_rect(x="10", y="10", width="40", height="40", fill="url(#full_diag)", stroke="#000000ff", stroke_width="2", roundedx="5", roundedy="5")

	# add a circle
	print "Adding circle"
	test.add_circle(centerx="40", centery="40", radius="15", fill="url(#full_diag)", stroke="#00ff00ff", stroke_width="0.5")

	# add an ellipse
	print "Adding ellipse"
	ellipse = test.add_ellipse(centerx="10", centery="40", radiusx="10", radiusy="20", fill="#ff00ffaa")

	# test some translation and rotation functions
	print "Testing transformation functions"
	ellipse.translate(30, -10)
	ellipse.rotate(5)

	# add a text element
	print "Adding text element"
	text = test.add_text(x="0", y="10", text="Testing...!", fill="#000000ff")
	print "Adding tspan"
	text.add_tspan(x="20", y="5", text="Boo!", fill="#ff0000ff")

	# add a polyline
	print "Adding polyline"
	polyline = test.add_polyline(x="0", y="0", fill="#00ff00ff")
	print "Adding polyline points"
	polyline.add_point(20, 0)
	polyline.add_point(20, 20)
	polyline.add_point(40,20)

	# save the file
	print "Saving SVG"
	test.save("./test.svg")

	print green("SVG Creation test completed")
	# this has to be the same no matter how called
	filename = argv[1]
	overlay_filename = argv[2]

	# set some defaults
	file_to_save = None
	x_position = 0
	y_position = 0

	# get the actual options
	if len(argv) == 4:
		file_to_save = argv[3]
	elif len(argv) in [5, 6]:
		x_position = argv[3]
		y_position = argv[4]
		if len(argv) == 6:
			file_to_save = argv[5]

	print "Overlaying: " + basename(filename) + " + " + basename(overlay_filename) + " -> " + (file_to_save and file_to_save or basename(filename))

	# load the files
	svg = SVGFile(filename)
	overlay_svg = SVGFile(overlay_filename)

	# do the overlay
	overlay(svg, overlay_svg, x_position, y_position)

	# save the new file
	svg.save(file_to_save)