Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

วิธีการวาดสตริงในแนวตั้งโดยใช้ฟังก์ชัน imagestringup () ใน PHP?


imagestringup() เป็นฟังก์ชัน inbuilt ใน 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 เก็บสตริงที่ต้องการเขียน

  • $สี − พารามิเตอร์นี้เก็บสีของภาพไว้

คืนค่า

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);
?>

ผลลัพธ์

วิธีการวาดสตริงในแนวตั้งโดยใช้ฟังก์ชัน imagestringup () ใน PHP?