ImageSetBackgroundColor : Just say no.

At work I'm using the CFImage tags in CF8 to manipulate images to create a rotating image carousel. For the images on the left and right I was shearing them to create a poor man's perspective (cfimage has no perspective function :-( ). The problem is that when you shear the rectangle, there's a new triangular area created in the image as the output of the function is still rectangular (that may not make sense if you haven't used the imageShear function, go try it, I'll wait). That new area has to have a color and by default it's white (I think, maybe black). If you want the sheared image to fit in nicely to your webpage you'll likely want that color to be set to something specific. I urge you not to think, "Oh, well, I'll just use ImageSetBackgroundColor to set the background color of the image."

Instead take the sheared image and paste it onto a rectangle that already is set to the color you want. Why? I'm glad you asked. First, if you're using a PNG image to shear, the ImageSetBackgroundColor function will cause the shear to be applied to only parts of the image. Here's the situation: I've got two images, one is of a happy little bunny, the second image has a two layers (one is a gradient, the other is a 75% transparent rectangle). The process I followed was to paste the layered image on top of the bunny, then shear the resulting image object. When this is accomplished without calling ImageSetBackgroundColor first all three pieces (bunny, gradient, and translucent rectangle) shear uniformly. When I call ImageSetBackgroundColor first, the translucent rectangle doesn't shear. Changing the type of PNG generated in Fireworks had no effect as far as I could tell.


About this entry