Skip to content

Instantly share code, notes, and snippets.

@kig
Created May 21, 2010 07:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kig/408601 to your computer and use it in GitHub Desktop.
Save kig/408601 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
USAGE = "dataurize filename [mimetype] > filename.dataURI"
require 'base64'
mime = ARGV[1] || `file -ib '#{ARGV[0].gsub(/'/, "'\\\\''")}'`.strip
STDOUT.write("data:#{mime};base64,")
File.open(ARGV[0], 'rb') {|f|
STDOUT.write(Base64.encode64(f.read(4500))) until f.eof?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment