Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created April 30, 2012 06:28
Show Gist options
  • Save tobiashm/2555987 to your computer and use it in GitHub Desktop.
Save tobiashm/2555987 to your computer and use it in GitHub Desktop.
SASS inline-color-image
require "sass"
require "chunky_png"
module Sass::Script::Functions
# Generates a data-url for a PNG created from the given color.
# Can be used to set a alpha-transparent background for IE8<
#
# @example
# background: url(inline-color-image(rgba(102, 54, 32, 0.5)));
def inline_color_image(color)
assert_type color, :Color
chunky_color = ChunkyPNG::Color.rgba color.red, color.green, color.blue, (color.alpha * 255).round
Sass::Script::String.new ChunkyPNG::Image.new(32, 32, chunky_color).to_data_url
end
declare :inline_color_image, [:color]
end
@tobiashm
Copy link
Author

This is now part of the sass-extras gem https://github.com/tobiashm/sass-extras

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment