Skip to content

Instantly share code, notes, and snippets.

@visnup
Created April 30, 2013 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save visnup/5486977 to your computer and use it in GitHub Desktop.
Save visnup/5486977 to your computer and use it in GitHub Desktop.
module ApplicationHelper
# a helper to get a data uri for an image asset
# e.g. <img src="<%= asset_data_uri('facebook.png') %>" />
def asset_data_uri(path)
asset = asset_paths.asset_for path, nil
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment