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

PHP – ตรวจสอบ True Color Image ด้วย imageistruecolor()

ฟังก์ชัน imageistruecolor() ใช้ตรวจสอบว่ารูปภาพที่กำหนดเป็น true-color image หรือไม่ True-color image แต่ละ pixel ระบุค่าสีด้วย RGB (Red, Green, Blue)

รูปแบบการใช้งาน (Syntax)

bool imageistruecolor(GdImage $image)

พารามิเตอร์

  • $image – รูปภาพที่ต้องการตรวจสอบ

ค่าที่คืนกลับ

คืน true หากเป็น true-color image false หากไม่ใช่ (เช่น palette-based หรือ grayscale)

ตัวอย่าง 1: True-color Image (RGB)

<?php
$img = imagecreatefrompng('C:\xampp\htdocs\Images\img44.png');
$istruecolor = imageistruecolor($img);
if ($istruecolor) {
    echo "The given input image is true-color";
}
?>

ผลลัพธ์

Input RGB image

PHP – ตรวจสอบ True Color Image ด้วย imageistruecolor()

The given input image is true-color.

ตัวอย่าง 2: Grayscale Image (ไม่ใช่ true-color)

<?php
$img = imagecreatefrompng('C:\xampp\htdocs\Gray.png');
$istruecolor = imageistruecolor($img);
if ($istruecolor) {
    echo "The given input image is not a true-color";
}
?>

ผลลัพธ์

Input grayscale image

PHP – ตรวจสอบ True Color Image ด้วย imageistruecolor()

The given input image is not a true-color image.