如何使用PHP中的imagestring()函數水平繪製文字字串圖像?

王林
發布: 2023-09-05 09:52:02
轉載
1199 人瀏覽過

imagestring() 是 PHP 中的內建函數,用於水平繪製字串。

Syntax

bool imagestring($image, $font, $x, $y, $string, $color)
登入後複製

Parameters

#imagestring() accepts six different parameters − $image, $font, $x, $y, $string, and $color.

  • $image − The $image parameter uses imagecreatetruecolor() function to create a blank 在給定的大小中的圖像。

  • $font$font參數用於設定字體大小值為1、2、3、4和5

    對於內建字體。

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

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

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

  • $color - 此參數儲存影像的顏色。

傳回值

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

範例1

<?php
   // Create the size and image by using imagecreate() function.
   $img = imagecreate(700, 300);

   // Set the background color of the image
   $background_color = imagecolorallocate($img, 0, 0, 255);

   // Set the text color of the image
   $text_color = imagecolorallocate($img, 255, 255, 255);

   // Function to create an image that contains the string.
   imagestring($img, 50, 180, 150, "Tutorialspoint", $text_color);
   imagestring($img, 30, 160, 120, "Simply Easy Learning", $text_color);
   header("Content-Type: image/png");
   imagepng($img);
   imagedestroy($img);
?>
登入後複製

輸出

如何使用PHP中的imagestring()函數水平繪製文字字串圖像?

#範例2

<?php
   // Create the size of the image or blank image
   $img = imagecreate(700, 300);

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

   // Set the text color of the image
   $text_color = imagecolorallocate($img, 255, 255, 0);

   // Function to create an image that contains a string.
   imagestring($img, 10, 30, 60,"Tutorialspoint:Simply Easy Learning", $text_color);
   header("Content-Type: image/png");
   imagepng($img);
   imagedestroy($img);
?>
登入後複製

輸出

如何使用PHP中的imagestring()函數水平繪製文字字串圖像?

以上是如何使用PHP中的imagestring()函數水平繪製文字字串圖像?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!