Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from kig/dataurize.rb
Created November 10, 2013 18:01
Show Gist options
  • Select an option

  • Save JT5D/7401579 to your computer and use it in GitHub Desktop.

Select an option

Save JT5D/7401579 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