Created
February 2, 2009 15:31
-
-
Save jimmac/56939 to your computer and use it in GitHub Desktop.
render gnome-power-manager icons
This file contains 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/env ruby | |
# the source svg needs to have a 'plate' layer with all the crop | |
# rects having a label with the output filename | |
require "rexml/document" | |
require "ftools" | |
include REXML | |
INKSCAPE = '/usr/bin/env inkscape' | |
SRC = "#{Dir.pwd}/svg/gpm-batteries.svg" | |
OUT = "#{Dir.pwd}/png" | |
def renderit | |
svg = Document.new(File.new(SRC, 'r')) | |
svg.root.each_element("//g[contains(@inkscape:label,'plate')]") do |icon| | |
if icon.attributes['inkscape:groupmode']=='layer' #only look inside layers, there may be pasted groups | |
icon.each_element("rect") do |box| | |
outfile = "#{box.attributes['inkscape:label']}.png" | |
dir = "#{OUT}/" + outfile.gsub(/\/[^\/]+$/,'') | |
cmd = "#{INKSCAPE} -i #{box.attributes['id']} -e \"#{OUT}/#{outfile}\" \"#{SRC}\" > /dev/null 2>&1" | |
File.makedirs(dir) unless File.exists?(dir) | |
system(cmd) unless File.exists?("#{OUT}/#{outfile}") | |
print "." | |
end | |
puts '' | |
end | |
end | |
end | |
renderit unless !File.exists?(SRC) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment