Skip to content

Instantly share code, notes, and snippets.

@nailor
Created September 20, 2011 12:13
Show Gist options
  • Save nailor/1228948 to your computer and use it in GitHub Desktop.
Save nailor/1228948 to your computer and use it in GitHub Desktop.
require 'sass'
module Sass::Script::Functions
def inline_image(image, type)
path = image.value
image_data = [data(path)].flatten.pack('m').gsub('\n', '')
declaration = "url('data:#{type};base64,#{image_data}')"
Sass::Script::String.new(declaration)
end
declare :inline_image, :args => [:string, :string]
protected
def data(path)
File.open(path, "rb") {|io| io.read}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment