in reply to gd, setpixel, and truecolor

You can't declare a truecolor image in GD, AFAIK; you have just created a GD/GD2 in memory internal representation of your original truecolor image file. This representation is indexed - at least, it appears to be so from the docs, never read the actual code myself - thus the need for color allocation. On output, the representation is converted to whatever format you need, truecolor or not.