Skip to content

Instantly share code, notes, and snippets.

@patrys
Forked from jimmac/rebrand.rb
Created December 13, 2012 14:42
Show Gist options
  • Save patrys/4276785 to your computer and use it in GitHub Desktop.
Save patrys/4276785 to your computer and use it in GitHub Desktop.
import glob
import os
from xml.etree import ElementTree
TEMP = './tmp.svg'
def rebrand(fname, brand):
svg = ElementTree.parse(fname)
for e in svg.iterfind(".//{http://www.w3.org/2000/svg}rect[@id='background']"):
e.set('style', 'fill:url(#%s);' % (brand,))
svg.write(TEMP)
for fname in glob.glob('*svg'):
print fname
rebrand(fname, "RHEL7")
#os.system("inkscape --vacuum-defs -l ../getting-started/C/figures/%s %s" % (fname, TEMP))
#os.unlink(TEMP)
#!/usr/bin/env ruby
require "rexml/document"
include REXML
def rebrand(fname, brand)
svg = Document.new(File.new(fname, 'r'))
temp =
svg.root.each_element("/svg/g/rect[@id='background']") do |e|
e.attributes["style"] = "fill:url(##{brand});"
puts e
end
temp_f = File.new(TEMP,'w+')
temp_f.puts svg
temp_f.close
end
TEMP = './tmp.svg'
Dir.glob("*svg") do |fname|
puts fname
rebrand(fname, "RHEL7")
system "inkscape --vacuum-defs -l ../getting-started/C/figures/#{fname} #{TEMP}"
File.delete(TEMP)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment