imagettftext

(PHP 4, PHP 5, PHP 7)

imagettftext锟斤拷 TrueType 锟斤拷锟斤拷锟斤拷图锟斤拷写锟斤拷锟侥憋拷

说锟斤拷

imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text ) : array

使锟斤拷 TrueType 锟斤拷锟藉将 指锟斤拷锟斤拷 text 写锟斤拷图锟斤拷

锟斤拷锟斤拷

image

锟斤拷图锟襟创斤拷锟斤拷锟斤拷(锟斤拷锟斤拷imagecreatetruecolor())锟斤拷锟截碉拷图锟斤拷锟斤拷源锟斤拷

size

锟斤拷锟斤拷某叽纭o拷锟斤拷锟� GD 锟侥版本锟斤拷为锟斤拷锟截尺寸(GD1锟斤拷锟斤拷悖拷锟斤拷锟斤拷叽纾℅D2锟斤拷锟斤拷

angle

锟角讹拷锟狡憋拷示锟侥角度o拷0 锟斤拷为锟斤拷锟斤拷锟斤拷锟揭讹拷锟斤拷锟侥憋拷锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷示锟斤拷时锟斤拷锟斤拷转锟斤拷锟斤拷锟斤拷 90 锟饺憋拷示锟斤拷锟斤拷锟斤拷锟较讹拷锟斤拷锟侥憋拷锟斤拷

x

锟斤拷 x锟斤拷y 锟斤拷锟斤拷示锟斤拷锟斤拷锟疥定锟斤拷锟剿碉拷一锟斤拷锟街凤拷锟侥伙拷锟斤拷锟姐(锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷陆牵锟斤拷锟斤拷锟斤拷 imagestring() 锟斤拷同锟斤拷锟斤拷 x锟斤拷y 锟斤拷锟斤拷锟剿碉拷一锟斤拷锟街凤拷锟斤拷锟斤拷锟较角★拷锟斤拷锟斤拷 "top left" 为 0, 0锟斤拷

y

Y 锟斤拷锟疥。锟斤拷锟借定锟斤拷锟斤拷锟斤拷锟斤拷叩锟轿伙拷茫锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟阶端★拷

color

锟斤拷色锟斤拷锟斤拷锟斤拷使锟矫革拷锟斤拷锟斤拷色锟斤拷锟斤拷值锟斤拷锟叫关闭凤拷锟斤拷莸锟叫э拷锟斤拷锟斤拷锟� imagecolorallocate()锟斤拷

fontfile

锟斤拷锟斤拷要使锟矫碉拷 TrueType 锟斤拷锟斤拷锟铰凤拷锟斤拷锟�

锟斤拷锟斤拷 PHP 锟斤拷使锟矫碉拷 GD 锟斤拷牟锟酵拷锟�锟斤拷 fontfile 没锟斤拷锟斤拷 / 锟斤拷头时锟斤拷 .ttf 锟斤拷锟斤拷锟接碉拷锟侥硷拷锟斤拷之锟斤拷锟斤拷锟揭伙拷锟节库定锟斤拷锟斤拷锟斤拷路锟斤拷锟叫筹拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷

锟斤拷使锟矫碉拷 GD 锟斤拷姹撅拷锟斤拷锟� 2.0.18 时锟斤拷一锟斤拷锟秸革拷锟街凤拷 锟斤拷锟斤拷锟角分号斤拷锟斤拷锟斤拷锟斤拷锟斤拷为锟斤拷同锟斤拷锟斤拷锟侥硷拷锟斤拷"路锟斤拷锟街革拷锟斤拷"锟斤拷锟斤拷小锟斤拷使锟斤拷锟剿达拷锟斤拷锟皆斤拷锟结导锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷息锟斤拷Warning: Could not find/open font锟斤拷锟斤拷锟斤拷影锟斤拷陌姹撅拷锟剿滴ㄒ伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟角斤拷锟斤拷锟斤拷锟狡讹拷锟斤拷锟斤拷锟斤拷锟斤拷锟秸革拷锟铰凤拷锟斤拷锟饺ワ拷锟�

锟杰讹拷锟斤拷锟斤拷锟斤拷锟斤拷宥硷拷锟斤拷诮疟锟斤拷锟酵伙拷锟侥柯硷拷隆锟斤拷锟斤拷锟斤拷小锟斤拷锟缴匡拷锟皆硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷狻�

<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' realpath('.'));

// Name the font to be used (note the lack of the .ttf extension)
$font 'SomeFont';
?>

text

UTF-8 锟斤拷锟斤拷锟斤拷谋锟斤拷址锟斤拷锟斤拷锟�

锟斤拷锟皆帮拷锟斤拷十锟斤拷锟斤拷锟斤拷锟街伙拷锟街凤拷锟斤拷示锟斤拷锟斤拷式为锟斤拷&#8364;锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫筹拷锟斤拷位锟斤拷 127 锟斤拷锟街凤拷锟斤拷UTF-8 锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷锟街憋拷哟锟斤拷荨锟�

锟斤拷锟斤拷实锟藉,锟斤拷锟斤拷 &copy; 锟角诧拷支锟街的★拷锟斤拷锟皆匡拷锟斤拷使锟斤拷 html_entity_decode() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷实锟斤拷为 UTF-8 锟街凤拷锟斤拷 锟斤拷锟斤拷 PHP 5.0.0 锟斤拷始 html_entity_decode() 锟斤拷始支锟街o拷

锟斤拷锟斤拷址锟斤拷锟斤拷锟绞癸拷玫锟侥筹拷锟斤拷址锟斤拷锟斤拷锟斤拷锟斤拷锟街э拷郑锟揭伙拷锟斤拷锟斤拷木锟斤拷谓锟斤拷婊伙拷锟斤拷址锟斤拷锟�

锟斤拷锟斤拷值

锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷 8 锟斤拷锟斤拷元锟斤拷锟斤拷锟斤拷锟绞撅拷锟斤拷谋锟斤拷锟斤拷锟斤拷母锟斤拷牵锟剿筹拷锟轿拷锟斤拷陆牵锟斤拷锟斤拷陆牵锟斤拷锟斤拷辖牵锟斤拷锟斤拷辖恰锟斤拷锟叫╋拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥憋拷锟侥讹拷锟酵角讹拷锟睫关o拷锟斤拷锟�"锟斤拷锟较斤拷"指锟斤拷锟斤拷锟斤拷水平锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷锟较角★拷

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
5.2.0 It is now possible to specify an hexadecimal entity in text.

锟斤拷锟斤拷

Example #1 imagettftext() 锟斤拷锟斤拷

锟斤拷锟斤拷锟叫的脚憋拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷色锟斤拷 400x30 锟斤拷锟斤拷 PNG 图锟斤拷锟斤拷锟斤拷锟叫猴拷色锟斤拷锟斤拷锟斤拷色锟斤拷影锟斤拷Arial 锟斤拷锟斤拷写锟斤拷"Testing..."锟斤拷

<?php
// Set the content-type
header('Content-Type: image/png');

// Create the image
$im imagecreatetruecolor(40030);

// Create some colors
$white imagecolorallocate($im255255255);
$grey imagecolorallocate($im128128128);
$black imagecolorallocate($im000);
imagefilledrectangle($im0039929$white);

// The text to draw
$text 'Testing...';
// Replace path by your own font path
$font 'arial.ttf';

// Add some shadow to the text
imagettftext($im2001121$grey$font$text);

// Add the text
imagettftext($im2001020$black$font$text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�

锟斤拷锟斤拷锟斤拷锟斤拷锟絠magettftext()

注锟斤拷

Note:

锟斤拷锟斤拷锟斤拷同时锟斤拷要 GD 锟斤拷锟� » FreeType 锟解。.

锟轿硷拷

  • imagettfbbox() - 取锟斤拷使锟斤拷 TrueType 锟斤拷锟斤拷锟斤拷谋锟斤拷姆锟轿�