Module: Sass::Extras::InlineColorImage

Defined in:
lib/sass/extras/inline_color_image.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/sass/extras/inline_color_image.rb', line 6

def self.included(base)
  base.declare :inline_color_image, [:color]
end

Instance Method Details

#inline_color_image(color) ⇒ Object

Generates a data-url for a PNG created from the given color. Can be used to set a alpha-transparent background for IE8<

Examples:

background: url(inline-color-image(rgba(102, 54, 32, 0.5)));


15
16
17
18
19
# File 'lib/sass/extras/inline_color_image.rb', line 15

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