Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/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