Created
May 25, 2013 14:28
-
-
Save easonhan007/5649264 to your computer and use it in GitHub Desktop.
encode a jpg image file to base64 string and display it in an html file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'base64' | |
binary = File.open(File.join('.', 'img.jpg'), 'rb') do |io| | |
io.read | |
end | |
encoded = Base64.encode64(binary) | |
printf('<img src="data:image/jpeg;base64,%s"></img>', encoded) | |
# ruby encode_img.rb > img.html | |
# open img.html with chrome or firefox |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment