如何在PHP中使用imagestringup()函式垂直繪製字串?


imagestringup()是PHP中的一個內建函式,用於垂直繪製圖像。

語法

bool imagestringup ($image, $font, $x, $y, $string, $color)

引數

imagestring()接受六個引數:$image、$font、$x、$y、$string和$color。

  • $image$image引數使用imagecreatetruecolor()函式建立給定大小的空白影像。

  • $font$font引數用於設定字型大小值,從1、2、3、4和5選擇內建字型,或使用imageloadfont()函式註冊的其他字型識別符號。

  • $x − 保持字型在水平X軸上的位置,左上角。

  • $y − 保持字型在垂直Y軸上的位置,頂部。

  • $string$string引數儲存要寫入的字串。

  • $color − 此引數儲存影像的顏色。

返回值

imagestring()成功時返回True,失敗時返回False。

示例

<?php
   // Create a 250*190 image using imagecreatetruecolor() function
   $img = imagecreatetruecolor(700, 300);

   // Set the background color of the image
   $bgcolor = imagecolorallocate($img, 122, 122, 122);

   // Fill background with above-selected color
   imagefill($img, 0, 0, $bgcolor);

   // Write the white color text
   $textcolor = imagecolorallocate($img, 255, 255, 255);
   imagestringup($img, 6, 130, 150, 'Hello World', $textcolor);

   // Output the picture to the browser
   header('Content-type: image/png');
   imagepng($img);
?>

輸出

更新於: 2021年8月9日

318次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.