努力用GD imagestring更改字体

时间:2013-05-05 17:57:46

标签: php gd

一直在试图改变字体&amp ;;字体大小,但我真的没有线索,我是新来的PHP和我在一个论坛上遇到的一些代码,并使它适用于我只需要找到一种方法来改变字体和字体大小,但一切我试过没有给我一个好结果..任何解决方案?请记住我是php的新手,如果你能尽可能多地解释你的答案,那么谢谢你

$im = imagecreatefrompng("image.png");
// if there's an error, stop processing the page:
if(!$im)
{
    die("");
}
// define some colours to use with the image
$black = imagecolorallocate($im, 80, 77, 77);
$font = 'cour.ttf';
// get the width and the height of the image
$width = imagesx($im);

$height = imagesy($im);



$textt = $_GET['textt'];
$dealer = $_GET['dealer'];
$purchase = $_GET['purchase']; 
$name = $_GET['name'];
$address = $_GET['address'];
$address1 = $_GET['address1'];

// store the text we're going to write in $textt
putenv('GDFONTPATH=' . realpath('cour.ttf'));


// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*strlen($textt) )/2;
$leftTextPos = ( $width - imagefontwidth($font)*strlen($dealer) )/2;
// finally, write the string:

imagestring($im,$font,$leftTextPos-210,$height-295,$textt,$black);
imagestring($im,$font,$leftTextPos-210,$height-165,$dealer,$black);
imagestring($im,$font,$leftTextPos-200,$height-115,$purchase,$black);
imagestring($im,$font,$leftTextPos-130,$height-70,$name,$black);
imagestring($im,$font,$leftTextPos-100,$height-50,$address,$black);
imagestring($im,$font,$leftTextPos-00,$height-50,$address1,$black);
// output the image
// tell the browser what we're sending it
Header('Content-type: image/png');
// output the image as a png
imagepng($im);
// tidy up
imagedestroy($im);
?>

1 个答案:

答案 0 :(得分:0)

您应该尝试使用imagettftext功能。