以下為引用的內容: //讀取目標檔案 $im = imagecreatefromjpeg("1[2].jpg"); //設定混合模式 imagealphablending($im, true); //讀取浮水印 $im2 = imagecreatefrompng("watermark.png"); //下面是我寫的字,可以不看 //$color = imagecolorallocate($im2, 0, 0, 0); //imagestring($im2, 12, 1, 1, "i love u jingjing", $color); //字結束 //拷貝浮水印到目標檔案 imagecopy($im, $im2, 5, 5, 0, 0, 220, 34); //輸出,可以輸出到檔案裡 imagejpeg($im); imagedestroy($im); imagedestroy($im1); ?> $im = imagecreatefromjpeg("1[2].jpg"); //$im = imagecreatefromgif("eee.gif"); //$im = imagecreatefrompng("1[2].png"); $black = imagecolorallocate ($im, 0, 140, 76); $red = imagecolorallocate ($im, 255, 0, 0); $string=chr(0xe5).chr(0xae).chr(0x89).chr(0xe5).chr(0xba).chr(0x86).chr(0xe6).chr(0x88).chr(0xbf).chr(0xe4).chr(0xba).chr(0xa7).chr(0xe7).chr(0xbd).chr(0x91); //imagestring ($im,12,10,10,$string,$red); imagettftext($im,20,0,4,30,$red,"fzdhtjw.ttf",$string); imagepng ($im); imagedestroy ($im); ?> //這個函數是把漢字轉換成utf-8後,就可以在gd中使用了! function gb2utf8($gb) { if(!trim($gb)) return $gb; $filename="gb2312.txt"; $tmp=file($filename); $codetable=array(); while(list($key,$value)=each($tmp)) $codetable[hexdec(substr($value,0,6))]=substr($value,7,6); $utf8=""; while($gb) { if (ord(substr($gb,0,1))>127) { $this=substr($gb,0,2); $gb=substr($gb,2,strlen($gb)); $utf8.=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080])); } else { $gb=substr($gb,1,strlen($gb)); $utf8.=u2utf8(substr($gb,0,1)); } } $ret=""; for($i=0;$i$ret.=chr(substr($utf8,$i,3)); return $ret; } function u2utf8($c) { for($i=0;$i$str=""; if ($c < 0x80) { $str.=$c; } else if ($c < 0x800) { $str.=(0xc0 | $c>>6); $str.=(0x80 | $c & 0x3f); } else if ($c < 0x10000) { $str.=(0xe0 | $c>>12); $str.=(0x80 | $c>>6 & 0x3f); $str.=(0x80 | $c & 0x3f); } else if ($c < 0x200000) { $str.=(0xf0 | $c>>18); $str.=(0x80 | $c>>12 & 0x3f); $str.=(0x80 | $c>>6 & 0x3f); $str.=(0x80 | $c & 0x3f); } return $str; } header("content-type: image/gif"); $im = imagecreate(400,300); $bkg = imagecolorallocate($im, 0,0,0); $clr = imagecolorallocate($im, 255,255,255); $fnt = "wb.ttf"; //include("gb2utf8.php"); $str = gb2utf8("中國"); imagettftext($im, 20, 0, 10, 20, $clr, $fnt, $str); imagegif($im); imagedestroy($im); ?>
|