-
-
Save seanhandley/5014904 to your computer and use it in GitHub Desktop.
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/env ruby | |
# extracts the embedded PNG data from .skitch SVG files | |
require 'nokogiri' | |
require 'base64' | |
require 'fileutils' | |
IMAGE_HEADER = "data:image/png;base64," | |
ARGV.each do |filename| | |
svg_document = Nokogiri::XML(File.open(filename)) | |
# get rid of the namespaces, facilitates the xpath search | |
svg_document.remove_namespaces! | |
# retrieve the href attribute that contains the image data | |
image_attribute = svg_document.xpath("//image/@href")[0] | |
# remove the header | |
image_data = image_attribute.value.slice(IMAGE_HEADER.length..-1) | |
png_filename = filename.gsub(/(.*)(\.skitch)/,'\1.png') | |
File.write(png_filename, Base64.decode64(image_data)) | |
FileUtils.touch(png_filename, :mtime => File.ctime(filename)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment