Skip to content

Instantly share code, notes, and snippets.

@ingeniarius
Created August 1, 2011 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ingeniarius/1118795 to your computer and use it in GitHub Desktop.
Save ingeniarius/1118795 to your computer and use it in GitHub Desktop.
Convert binary file to data URI base64 encoded
require 'base64'
file = ARGV[0]
mimetype = `file -b --mime-type #{file}`.gsub(/\n/,'')
puts "data:#{mimetype};base64," << Base64.encode64(File.read(file)).gsub(/\n/, '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment