DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Svg Base64 Image Extractor
// description of your code here
require "nokogiri"
doc = Nokogiri::XML(File.read(ARGV[0]))
(doc/"image").each do |image|
type, base64 = image.attr("href").split(",", 2)
extension = type[/^data:image\/([^;]+);/, 1]
extension.sub!(/^jpeg$/, "jpg")
image_content = base64.unpack("m*").first
File.open(image.attr("id")+"."+extension, "w") { |f| f.write(image_content) }
end





