Görüntü dize sadece siyah bir arka plan üretir

2 Cevap php

Ben gerçekten bir sorun bu düzeltmek için nasıl bulma yaşıyorum. Ben siyah arka planı değiştirmek için görünmüyor olabilir. Nasıl mümkün?

$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);

2 Cevap

Kullanın:

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

User279470 cevabını birleştirilerek:

$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);