protected function gdImageBackground($image, $bgcolor)
{
if ($bgcolor == 'transparent') {
imagesavealpha($image, true);
$bgcolor1 = imagecolorallocatealpha($image, 255, 255, 255, 127);
} else {
list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
$bgcolor1 = imagecolorallocate($image, $r, $g, $b);
}
imagefill($image, 0, 0, $bgcolor1);
}