imagestring() เป็นฟังก์ชัน inbuilt ใน 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 เก็บสตริงที่ต้องการเขียน
-
$สี − พารามิเตอร์นี้เก็บสีของภาพไว้
คืนค่า
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);
?> ผลลัพธ์

ตัวอย่างที่ 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);
?> ผลลัพธ์
