Layout woes.
Lets say you want to construct a layout with layered PNGs, but you need it to be backwards compatible with older browsers because that’s the nature of your synagogue membership and their computers.
First, let me warn that this is expensive if you run this each and every time an IE user comes to your site. I would always opt for the client-side PNGFix scenarios, but there are times when your design is just so cool but not possible to quickly make compatible with the variety of browsers out there.
Here’s a simple version that seems to work for my site with IE 6.
If ( ListGetAt(CGI.HTTP_USER_AGENT,2,";") eq "MSIE 6.0"){
// above checks for IE 6 in the CGI variable, below checks our "cache" to ensure we don't already
// have said file
if(not FileExists(ExpandPath("images/headercache/test.png"))) {
// this now creates our working image, with the appropriate dimensions
BlockImage = ImageNew("",800,194);
// in CF9, not sure in CF8, ImageNew can create an object out of existing files, which is what we do here
LeftImage = ImageNew("images/graphic_bar_left.png");
NavImage = ImageNew("images/graphic_bar_nav_bg.jpg");
LogoImage = ImageNew("images/graphic_bar_logo.png");
BackgroundImage = ImageNew("images/frontpage/mainsanctuary.jpg");
//ImagePaste lets us take the image, the first argument, and paste the image in the second argument
// at the x and y (third and fourth arguments) respectively.
ImagePaste(BlockImage,BackgroundImage,0,0);
ImagePaste(BlockImage,LeftImage,0,0);
ImagePaste(BlockImage,NavImage,72,0);
ImagePaste(BlockImage,LogoImage,198,0);
// we now write that image to file. I could have opted to write it to browser, but figuring this
// this process could be quite expensive, I'd rather check against the file system first. In my real
// world implementation, the background image is randomly pulled from a list of objects, so I'd have
// variable filenames for all of this.
ImageWrite(BlockImage,"images/headercache/test.png");
}
}
ColdFusion is very, very nice at times.