Skip to content

Instantly share code, notes, and snippets.

@gylaz
Created March 26, 2015 18:04
Show Gist options
  • Save gylaz/2b5d26480ce62c7587c1 to your computer and use it in GitHub Desktop.
Save gylaz/2b5d26480ce62c7587c1 to your computer and use it in GitHub Desktop.
Asset Data URI -- Convert image to binary data
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