I\'m pretty sure I need to use imagefilledrectangle in order to get a white background instead of black on this... just not sure how. I\'ve tried a few ways.
imagefill() uses flood fill, which is quite slow compared to just painting a color in a rectangle without regard for the content of the image. So imagefilledrectangle() will be a lot quicker.
// get size of target image
$width = imagesx($targetImage);
$height = imagesy($targetImage);
// get the color white
$white = imagecolorallocate($targetImage,255,255,255);
// fill entire image (quickly)
imagefilledrectangle($targetImage,0,0,$width-1,$height-1,$white);
Speed is often a consideration when writing code.
UPDATE (2020): Please see this answer below for a faster fill than imagefill: https://stackoverflow.com/a/32580839/1005039
ORIGINAL
From the PHP manual entry for imagefill:
$image = imagecreatetruecolor(100, 100);
// set background to white
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);
$targetImage = imagecreatetruecolor($thumbw,$thumbh);
// get the color white
$color = imagecolorallocate($targetImage, 255, 255, 255);
// fill entire image
imagefill($targetImage, 0, 0, $color);
imagecolorallocate: http://www.php.net/manual/en/function.imagecolorallocate.php
imagefill: http://php.net/manual/en/function.imagefill.php