php GD create a transparent png image

前端 未结 3 1038
Happy的楠姐
Happy的楠姐 2020-11-27 06:00

I\'m trying to create a transparent png image and layer various other pngs and jpgs to create a final png with transparency. I\'m having trouble creating my initial empty tr

3条回答
  •  眼角桃花
    2020-11-27 07:00

    This code worked for me:

    $img=imagecreatetruecolor(180,20);
    imagealphablending($img,false);
    
    $col=imagecolorallocatealpha($img,255,255,255,127);
    imagefilledrectangle($img,0,0,180,20,$col);
    imagealphablending($img,true);
    
    $font=$_SERVER["DOCUMENT_ROOT"].'/fonts/Arial.ttf';
    $color = imagecolorallocate($img, 140, 173, 209);
    imagettftext($img,11,0,5,14,$color,$font,'Text goes here'); 
    
    header('Content-Type: image/png');
    imagealphablending($img,false);
    imagesavealpha($img,true);
    imagepng($img);
    

提交回复
热议问题