The Rails Way: Painless PNG in Ruby on Rails
The Painless PNG plugin allows your Rails application to support PNG images with transparencies for Internet Explorer 5.5+ through 6.x without changing existing code.
Quick fix for the impatient
For the impatient here’s the quick fix to solve your worries:
ruby script/plugin install \
http://svn.wheremydogs.at/painless_png/tags/painless_png
Yes, that’s right — it’s all you have to do.
The Painless PNG plugin transparently supports PNG images in Ruby on Rails with the image_tag method. You don’t have to change your existing code.
Can I see the plugin in action?
Sure, we rely heavily on it at our library of the world’s finest books and at our code snippets collection.
Background
PNG images are a blessing and a curse to web developers. They allow for high-resolution, compact graphics with beautiful transparency support. But the alpha transparency doesn’t work out of the box in Internet Exploer 5.5+ and 6.x, a bane to web developers world-wide.
This plugin solves the curse part and leaves only the blessing.
How does it work?
The Painless PNG plugin monkey patches the image_tag method such that
- If the browser is Internet Explorer 5.5 or 6.x then it uses the AlphaImageLoader filter method prescribed by Microsoft
- For all other browsers it uses the default
image_tagmethod from the Rails framework
This happens behind the scenes, transparently to your Rails application.
Sounds too good to be true, where’s the catch?
For HTML, there’s none. That is, provided you’ve been using the image_tag method to place your images rather than hand-coding <img> tags.
The only exception is that the plugin won’t work for PNG images used in CSS stylesheets.
Like it? Support us!
The Painless PNG plugin is released under the flexible MIT License, so you can basically do what you want with provided you keep the copyright in tact.
If you like and use it, we’d love to know—please drop us an email at contact@wheremydogs.at.
Also, please support us by visiting and spreading the word of our library of the world’s finest books and at our code snippets collection.
Problems? Found a bug?
Please let us know if you experience problems using the Painless PNG or if you think you’ve found a bug.
For us to fix any problems or bugs, please send the code you used and the exact error messages by email to philipp at wheremydogs.at.