$img=imagecreatetruecolor(50,20); 
 $color=imagecolorallocate($img,204,204,204);
 imagestring($img,5,rand(0,15),rand(0,15),$arr1,$color);
 header("Content-type: image/jpeg");
 imagejpeg($img);现在背景色是黑色。怎样改它???

解决方案 »

  1.   

    <?php
    $img=imagecreate(50,20); 
    $color=imagecolorallocate($img,204,204,204);
    imagestring($img,5,rand(0,15),rand(0,15),$arr1,$color);
    header("Content-type: image/jpeg");
    imagejpeg($img);
    ?> 
      

  2.   

     $img=imagecreatetruecolor(500,200); 
     $color=imagecolorallocate($img,255,0,0);
     $bg   = imagecolorallocate($img,255,255,0);
     imagefilledrectangle($img,0,0,500,200,$bg); //画个大小一致矩形充当背景
     imagestring($img,5,rand(0,15),rand(0,15),$arr1='hello world',$color);
     header("Content-type: image/jpeg");
     imagejpeg($img);
      

  3.   

    imagefill -- 区域填充
    说明
    bool imagefill ( resource image, int x, int y, int color )
    imagefill() 在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。 例 1. imagefill() 例子<?php$im = imagecreatetruecolor(100, 100);// 将背景设为红色
    $red = imagecolorallocate($im, 255, 0, 0);
    imagefill($im, 0, 0, $red);header('Content-type: image/png');
    imagepng($im);
    imagedestroy($im);
    ?>