如果你用
int imagecreatefromgif(string filename);
來取出一張 gif 格式圖形,當背景或者基本的畫布樣本使用,在其上繪制圖形,請注意:
如果這個文件中沒有的色素,你將不能使用。
解決方法,你可以用
int imagecreate(int x_size, int y_size);
建立一張全空的圖形。在其上繪制圖形。將黑色作為透明色。
這個新建的圖形要和原圖形大小相同,絕對位置相同,將其放在原圖形上方,就可以了。
<img border="0" src="http://edu.cnzz.cn/newsinfo/1.gif" width="200" height="300">
原圖形文件
<img border="0" src="photo.php" width="200" height="300">
全空文件 photo.php
photo.php 的代碼:
<?php
header("content-type: image/gif");
$im = imagecreate(200,300);
$black = imagecolorallocate($im, 0,0,0);
$red = imagecolorallocate($im, 255,0,0);
$blue = imagecolorallocate($im, 0,0,255);
imagerectangle($im,100,200,150,200,$red) ;
imagestring($im,2,120,150,"aaaaaaaa",$blue);
imagecolortransparent($im,$black);
//將黑色作為透明色
imagegif($im);
imagedestroy($im);
?>