Skip to content

Instantly share code, notes, and snippets.

@delba
Last active December 17, 2015 08:59
Show Gist options
  • Select an option

  • Save delba/5584179 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5584179 to your computer and use it in GitHub Desktop.
Inline image with ruby
# data:[<MIME-type>][;charset=<encoding>][;base64],<data>
require 'base64'
file = File.new('my_file.png')
filename = File.basename(file)
mime_type = %x[file --brief --mime-type #{filename}].chomp
data = Base64.encode64(file.read).delete("\n")
# uuencode [-m] [ source_file ] remotedest
# uudecode [-o outfile] [ encoded_file ]
result = "data:#{mime_type};base64,#{data}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment