Skip to content

Instantly share code, notes, and snippets.

@andreiglingeanu
Forked from visnup/asset_data_uri.rb
Created October 6, 2015 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreiglingeanu/920aa9227ab6f33d3dc2 to your computer and use it in GitHub Desktop.
Save andreiglingeanu/920aa9227ab6f33d3dc2 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