New version of rgba.php is out!

It’s been a while since I posted my little server-side solution for cross-browser RGBA colors (in a nutshell: native rgba for the cool browsers that support it, a PHP-generated image for those that don’t). For features, advantages, disadvantages etc, go see the original post. In this one I’ll only discuss the new version.

So, since it’s release I’ve received suggestions from many people regarding this script. Some other ideas were gathered during troubleshooting issues that some others faced while trying to use it. I hope I didn’t forget anything/anyone :)

Changelog (+credits):

  1. You may now specify the size of the generated image (thanks Sander Arts!)
  2. If the PHP version is below 5.1.7 the call to imagepng() uses 2 parameters instead of 4, to workaround the bug found by Bridget (thanks Chris Neale for suggesting the use of phpversion()!)
  3. Added error_reporting() to only allow for fatal errors and parse errors to go through (I should had done this anyway but I completely forgot). This solves an issue that Erin Doak pointed out, since they had set up notices to be displayed and even a reference to an undefined index made the whole script collapse.
  4. Mariotti Raffaele pointed out that apache_request_headers() was not defined in all PHP installations. After looking into it a bit, I found out that it’s available only when PHP is installed as an Apache module. After some more research it turned out that the only way to get the If-Modified-Since header otherwise is an .htaccess, so I  ruled that out (It would complicate the workaround I think and I doubt all hosts allow .htaccess (?). On the other hand, an .htacess would also allow for some URL rewriting goodness… Hmmm… Should I consider this?). So, if the function is not available, it serves the file with an 200 response code every time, instead of just sending a 304 response when the If-Modified-Since header is present.
  5. Igor Zevaka for pointing out that the Expires header wasn’t a valid HTTP date.

Links

rgba.php

Demo

Enjoy :) and please report any bugs!

  • http://www.creativeg.gr Basilakis

    Oh lea, u drive me crazy! That is a greate tool and to say the truth, i have missed it when u first posted it.

    Combining it with a good UI, it can be easilly used for option templates to WordPress (sorry, but i am wp addicted :P)

  • http://www.somethingorothersoft.com Igor Zevaka

    Thanks heaps for this, it’s such a time saver transforming layout for proper browsers to work in IE :))

    One thing I noticed was that the Expires time does not conform to HTTP spec according to RED(Has to be “01 Jan…”):

    http://redbot.org/?uri=http%3A%2F%2Fwww.somethingorothersoft.com%2Fcolors%2Frgba.php%3Fr%3D14%26g%3D32%26b%3D59%26a%3D40

    I don’t think this causes any issues, it just came up as I was troubleshooting image caching in Chrome.

  • http://leaverou.me Lea Verou

    Happy new year Igor!

    Thanks, zip updated :-)

  • Jennie

    Thanks, Lea! I was having trouble with the old script (it would break after initially loading… I think related to undefined apache_request_headers() as you pointed out). This cleared everything up. RGBA in IE the easy way… makes me very happy!

  • Pingback: Bulletproof, cross-browser RGBA backgrounds, today « Lea Verou

  • Poco

    Thanks for this!

    Also, why don’t you allow for urls like this?: rgba.php?1,2,3,4

    I don’t think these would have to be urlencoded, and it would be easier to read.

  • http://www.shambanet.com Suso Guez

    Brilliant idea, very useful. I’m using it right now for my next redesign!

    Thanks!

  • http://www.pushpinderbagga.com/ Pushpinder

    Thanks a ton!

  • http://www.etheya.com Brian

    Only thing about this that i find slightly confusing.. is that say you use

    background: url(rgba.php?color_r=46&g=46&b=50&a=30) repeat;
    background: rgba(46,46,50, 0.3);

    They end up being 2 totally different colours.. so its hard to get the right combination to keep the same colours using the 2 methods..

  • http://www.etheya.com Brian

    Take that back… not sure how i ended up with the word color in there… all is well :-)

  • http://leaverou.me Lea Verou

    Yeah, the color_ part was unnecessary and you ended up not specifying r this way.

    By the way, one feature I’d like to implement in the next version is making the syntax more similar to the CSS one, like rgba.php/rgba(46,46,50,0.3) instead of rgba.php?r=46&g=46&b=50&a=30

  • Pingback: rgba.php v1.2: Improved URL syntax, now at Github « Lea Verou

  • http://leaverou.me Lea Verou

    Since a new version is out, comments closed on this one. Please direct any comments to the post for the new version or, even better, to the issues section at Github.