here's a small tool i made a while back to convert images to data
format meant to be embedded inside web apps.
# image2base64.rb
require 'base64'
class Convert
attr_reader :loaded_file
attr_reader :filename
def initialize(filename)
@filename=filename
@loaded_file = File.open( filename, "rb" ).read
end
def convert
Base64.encode64(@loaded_file).gsub(/\n/,'')
end
def to_s
"data:image/
#{File.basename(@filename).split(".").pop};base64,"<<self.convert
end
end
puts conv=Convert.new(ARGV[0])
------------- end code -------------------------
usage and description:
http://groups.google.com/group/object_id/web/inline-image-files-to-data-uri-scheme