Created
August 20, 2012 13:53
-
-
Save tobiashm/3404237 to your computer and use it in GitHub Desktop.
Generates a data-url for a PNG created from the given color.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is now part of the sass-extras gem https://github.com/tobiashm/sass-extras