<?php header('Content-type:image/png');
$n = "总统大印"; //四个汉字
$f = "simkai.ttf"; //字体:无需改:需要字体文件
$w = 600; //宽度:建议不改
$b = $w/12; //边框宽度:无需改
$z = ($w-$b*1.5)/3; //字体宽度:无需改
$img = imagecreatetruecolor($w, $w);
$bg1 = imagecolorallocate($img, 255, 0, 0);
imagefill($img, 0, 0, $bg1);
$img1 = imagecreatetruecolor($w-$b, $w-$b);
$bg2 = imagecolorallocate($img1, 255, 255, 255);
imagefill($img1, 0, 0, $bg2);
imagecopymerge($img, $img1, $b/2, $b/2, 0, 0, $w-$b, $w-$b, $w-$b*2);
imagettftext($img,$z,0,$w/2,$w/2-$b, $bg1, $f, mb_substr($n,0,1));
imagettftext($img,$z,0,$w/2,$w-$b*1.5, $bg1, $f, mb_substr($n,1,1));
imagettftext($img,$z,0,$b,$w/2-$b, $bg1, $f, mb_substr($n,2,1));
imagettftext($img,$z,0,$b,$w-$b*1.5, $bg1, $f, mb_substr($n,3,1));
imagepng($img);
imagedestroy($img);
?>
20行PHP代码实现中文四字方形印章功能