如何使用PHP中的imagestring()函式水平繪製文字字串影像?
imagestring()是PHP中的一個內建函式,用於水平繪製字串。
語法
bool imagestring($image, $font, $x, $y, $string, $color)
引數
imagestring() 接受六個不同的引數:$image,$font,$x,$y,$string和$color。
$image − $image引數使用imagecreatetruecolor()函式建立指定大小的空白影像。
$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); ?>
輸出
.jpg)
示例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); ?>
輸出
.jpg)
廣告
資料結構
網路
關係資料庫管理系統(RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP