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

ฟังก์ชัน imagechar() ใน PHP


ฟังก์ชัน imagechar() วาดตัวอักษรแนวนอน (Horizontal) บนภาพ

ไวยากรณ์

bool imagechar(img, font, x, y, ch, color)

พารามิเตอร์

  • img: ภาพจาก imagecreatetruecolor()
  • font: ขนาดฟอนต์
  • x: พิกัด X
  • y: พิกัด Y
  • c: ตัวอักษรที่จะวาด
  • color: สีจาก imagecolorallocate()

คืนค่า

TRUE สำเร็จ FALSE ล้มเหลว

ตัวอย่าง

<?php 
$img = imagecreate(400, 300); 
$str = 'Demo'; 
$bgcolor = imagecolorallocate($img, 30, 80, 70); 
$textcolor = imagecolorallocate($img, 255, 255, 255); 
imagechar($img, 80, 100, 90, $str, $textcolor); 
header('Content-type: image/png'); 
imagepng($img); 
?>

ผลลัพธ์

ฟังก์ชัน imagechar() ใน PHP

ตัวอย่างที่ 2

<?php 
$img = imagecreate(350, 270); 
$str = 'Example'; 
$bgcolor = imagecolorallocate($img, 70, 100, 130); 
$textcolor = imagecolorallocate($img, 200, 195, 210); 
imagechar($img, 100, 50, 70, $str, $textcolor); 
header('Content-type: image/png'); 
imagepng($img); 
?>

ผลลัพธ์

ฟังก์ชัน imagechar() ใน PHP