<?php
header("content-type:image/png;");
$str=iconv("UTF-8","GB2312","aaaaaa啊啊");
$font_size=10;
$font='simhei.ttf';
$Size=imagettfbbox($font_size,0,$font,$str);
$w = $Size [4];        //获取文字宽度
$h = abs( $Size [7] ); //获取文字高度
$img=ImageCreate($w,$h);
$bgcolor=ImageColorAllocate($img,204,204,204);
$red=ImageColorAllocate($img,204,204,204);
$bgcolortrans=ImageColorTransparent($img,$bgcolor);
imagettftext($img,10,0,0,$h,$red,$font,$str);
ImagePng($img);
ImageDestroy($img);?>
求教