Created
March 26, 2015 18:04
-
-
Save gylaz/2b5d26480ce62c7587c1 to your computer and use it in GitHub Desktop.
Asset Data URI -- Convert image to binary data
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
def asset_data_uri(path) | |
asset = Rails.application.assets.find_asset(path) | |
data = Base64.encode64(asset.source) | |
"data:#{asset.content_type};base64,#{Rack::Utils.escape(data)}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment