Created
March 18, 2013 17:20
-
-
Save bf4/5188994 to your computer and use it in GitHub Desktop.
Image to Data URI in ruby
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
- img_url = "http://example.com/image.jpg" | |
- img_type = img_url.split('.')[-1] | |
- img_binary = open(img_url).read | |
- img_data = ActiveSupport::Base64.encode64(img_binary).gsub("\n", '') | |
%img{src: "data:image/#{img_type};base64,#{img_data}"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
img_data = ActiveSupport::Base64.encode64(img_binary).gsub("\n", '')
replace toimg_data = Base64.strict_encode64(img_binary)