imagefttext()函數是PHP中的一個內置函數,用於使用FreeType 2使用字體將文本寫入圖像。
用法:
array imagefttext( resource $image, float $size, float $angle,
              int $x, int $y, int $color, string $fontfile,
              string $text, array $extrainfo )
參數:該函數接受上述和以下所述的九個參數:
- $image:它指定要處理的圖像。
 - $size:它指定要使用的字體大小(以磅為單位)。
 - $angle:它以度為單位指定角度。
 - $x:它指定x坐標。
 - $y:它指定y坐標。
 - $color:它指定文本所需顏色的索引。
 - $fontfile:它指定要使用的字體。
 - $text:它指定要寫入的文本。
 - $extrainfo (Optional):它指定了額外的信息。
 
返回值:該函數成功返回一個數組。
以下示例說明了PHP中的imagefttext()函數。
範例1:
<?php 
  
// Create an empty image 
$im = imagecreatetruecolor(800, 250); 
  
// Add text using a font from local file 
$dataArr = imagefttext($im, 0, 0, 10, 10,  
                       imagecolorallocate($im, 0, 150, 0),  
                       './Pacifico.ttf', 'GeeksforGeeks'); 
  
// Output to browser 
print("<pre>".print_r($dataArr, true)."</pre>"); 
?>輸出:
Array
(
    [0] => 8
    [1] => 12
    [2] => 18
    [3] => 12
    [4] => 18
    [5] => 7
    [6] => 8
    [7] => 7
)
程序2:
<?php 
  
// Create an empty image 
$im = imagecreatetruecolor(800, 250); 
  
// Add text using a font from local file 
imagefttext($im, 50, 0, 100, 100,  
            imagecolorallocate($im, 0, 150, 0),  
            './Pacifico.ttf', 'GeeksforGeeks'); 
  
// Output to browser 
header('Content-Type:image/png'); 
imagepng($im); 
imagedestroy($im); 
?>輸出:

參考: https://www.php.net/manual/en/function.imagefttext.php
相關用法
- PHP each()用法及代碼示例
 - p5.js second()用法及代碼示例
 - CSS url()用法及代碼示例
 - p5.js pow()用法及代碼示例
 - PHP next()用法及代碼示例
 - d3.js d3.map.set()用法及代碼示例
 - PHP pow( )用法及代碼示例
 - CSS var()用法及代碼示例
 - p5.js day()用法及代碼示例
 - PHP Ds\Set xor()用法及代碼示例
 - d3.js d3.set.has()用法及代碼示例
 - p5.js hue()用法及代碼示例
 
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagefttext() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
