Compass plugin for providing cross-browser compatible RGBA support by creating transparent PNGs on the fly for browsers that don't support RGBA. Uses the pure Ruby ChunkyPNG library for hassle free install and deployment.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit ahead, 13 commits behind aaronrussell:master.
Latest commit a708ff4 Feb 8, 2012 1 Jamie Kite Jamie Kite README clarification for Rails 3.1
For anyone else who is running into issues with the asset pipeline and rbgapng.

README.md

rgbapng - Compass plugin

rgbapng is a Compass plugin for providing cross-browser* compatible RGBA support. It works by creating single pixel alpha-transparent PNGs on the fly for browsers that don't support RGBA. It uses the pure Ruby ChunkyPNG library resulting in hassle-free installation and deployment.

Installation

Installation is simple via Ruby Gems. Compass and ChunkyPNG are required.

gem install compass-rgbapng

Using rgbapng with your Compass project and Rails 3.1

To use rgbapng with your Rails 3.1 project, add the following to your application.rb:

config.assets.paths << "#{Gem.loaded_specs['compass-rgbapng'].full_gem_path}/lib/"

And then import the mixins to your SASS/SCSS files:

@import "rgbapng";

If you're on <= Rails 3.0.x

To use rgbapng with your <= Rails 3.0 project, require the plugin from your Compass configuration:

require "rgbapng"

Configurable variables

There is a single variable that defines the path to which your PNG images will be saved. This defaults to rgbapng inside your Compass images directory. Change the path globally with:

$rgbapng_path: 'my_pngs';

Mixins

There are two mixins available to you.

rgba-background($color, [$path])

Sets the background property to use the RGBA value, falling back to the compiled PNG.

@include rgba-background(rgba(0,0,0,0.75));

Compiles to:

background: url('/images/rgbapng/000000bf.png?1282127952');
background: rgba(0, 0, 0, 0.75);

rgba-background-inline($color)

Sets the background property to use the RGBA value, falling back to a base64 encoded image data.

@include rgba-background-inline(rgba(0,0,0,0.75));

Compiles to:

background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNh2A8AAM4AxOSyusMAAAAASUVORK5CYII=');
background: rgba(0, 0, 0, 0.75);

Functions

There are two Sass::Script functions which can be used in your SASS:

# Creates the single pixel PNG image
# Returns a String of the image path and filename
png_pixelate(color, [dir])

# Returns a String of the base64 encoded image data
png_base64(color)

* Cross-browser? Really?

OK, caveat time. When I say "cross-browser", what I really mean is all browsers that either natively support RGBA or support alpha-transparent PNGs. What I don't mean, is IE6. If alpha-transparency in IE6 is important to you, here are some suggestions:

The choice is yours.

Credit where it's due

Copyright

Copyright (c) 2010 Aaron Russell. See LICENSE for details.