tags:

views:

90

answers:

2

Now it's black.

function show(){
    $word=array("a","b","c","d","e","f");
    $name=$word[rand(0,5)];
    $im=imagecreatetruecolor(62,20);
    $black=imagecolorallocate($im,rand(20,100),rand(20,100),rand(20,100));
    $white=imagecolorallocate($im,255,255,255);

    imagettftext($im,14,1,15,17,$white,'simkai.ttf',$name);

    for($i=0;$i<200;$i++)
    {
        $randcolor  =  ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
        imagesetpixel($im,  rand()%70  ,  rand()%30  ,  $randcolor);
    }
    header("content-type: image/jpeg");
    imagejpeg($im);
}
+1  A: 

if you iterate over the pixels and know which color is the ''background'', just add a condition. But a better aproach might be to use an image with transparency for the background.

Rasmus Kaj
he seems to use jpeg which means there is no transparency would be another story with png
RageZ
+2  A: 

you can use imagefill to fill the background with a give color. Also please not you add the $black variable but you never use it ? is that normal ?

function show(){
    $word=array("a","b","c","d","e","f");
    $name=$word[rand(0,5)];
    $im=imagecreatetruecolor(62,20);
    $black=imagecolorallocate($im,rand(20,100),rand(20,100),rand(20,100));
    $white=imagecolorallocate($im,255,255,255);
    imagefill ( $im , 0 ,0 , 0 )
    imagettftext($im,14,1,15,17,$white,'simkai.ttf',$name);

    for($i=0;$i<200;$i++)
    {
           $randcolor  =  ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
           imagesetpixel($im,  rand()%70  ,  rand()%30  ,  $randcolor);
    }
    header("content-type: image/jpeg");
 imagejpeg($im);
}
RageZ