MSIE 6, PNG, and Web Server 7
By jmccabe on Oct 02, 2007
MSIE 6 handles PNG Alpha Channels really badly. For years now I've not used them because of MSIE 6's poor implementation, and this means modern browsers that can handle them have not been working at their best while I designed with badness in mind.
"Stupid MSIE 6," I'd grumble as I made yet another low bit-depth image, edges aliased to an "average" background color, a single background color. "I was making GIF images like this in 1996. When does The Future start?"
So now I've decided to just present craptacular images to MSIE 6 and let all the rest of the browsers in the world (including MSIE 7) get that Alpha Channel Loving they crave. Here's how I did it without have to modify a single HTML file or PHP application.
Web Server 7.0's spiffy IF/Then/Else syntax lets me do conditional request processing based on a large number of variables (and would let me define my own for later evaluation if needed). I've taken advantage of this feature to selectively send crappy graphics to MSIE 6 and send nice 8-bit+Alpha PNG images to everyone else with this stanza (placed below the final NameTrans):
<If $browser =~ 'MSIE 6' and $uri =~ '\^.\*\\.png$' and $uri !~ '_low\\.png$' and not $restarted and $path =~ '(.\*)\\.png' > PathCheck fn="set-variable" $new_path="$1_low.png" <If -e $new_path and $uri =~ '(.\*)\\.png' > PathCheck fn="restart" uri="$1_low.png" </If> </If>
This evaluates a request by evaluating four conditions:
- Is the browser MSIE 6?
- And is the file being requested a PNG file?
- And the PNG file is not a file named SOMETHING_low.png?
- And the request has not already been restarted intnerally
- And a low-quality copy of the requested file does exist?
If all of these conditions evaluate to true then the enclosed PathCheck is executed. The PathCheck silently serves a low quality form of the graphic (name SOMETHING_low.png) rather than the Alpha Channel Goodness that everyone else gets (called SOMETHING.png). In my HTML/PHP/JSP/Whatever I just use an image tag pointing to SOMETHING.png and let Web Server worry about whether MSIE 6 is getting the Alpha Channel Goodness or low quality version of the file.
The more I use it the more I'm loving Web Server 7. Yay!