Phil Jackson
Phil Jackson

Reputation: 10288

String to image only produces a black background

I'm really having a problem finding out how to fix this. I cannot seem to change the background from black. How is it possible?

$string = "foo";
$font  = 4;
$width  = ImageFontWidth($font) * strlen($string);
$height = ImageFontHeight($font);
$im = @imagecreatetruecolor ($width,$height);
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 0, 0, $string, $textcolor);
imagegif($im, 'somefile.gif', 8);
imagedestroy($im);

Upvotes: 1

Views: 258

Answers (2)

Phil Jackson
Phil Jackson

Reputation: 10288

Incorporating user279470's answer:

$string = "foo";
$font  = 4;
$width  = ImageFontWidth($font) * strlen($string);
$height = ImageFontHeight($font);
$im = @imagecreatetruecolor ($width,$height);
$bg = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 0, 0, $string, $textcolor);
imagepng($im, 'somefile.png', 8);
imagedestroy($im);

Upvotes: 0

user279470
user279470

Reputation: 454

Use:

imagefill($im, 0, 0, $bg);

Upvotes: 1

Related Questions