imageistruecolor() เพื่อค้นหาว่ารูปภาพว่าเป็นรูปภาพ truecolor หรือไม่
ฟังก์ชัน imageistruecolor() เป็นฟังก์ชันหนึ่งที่ทำหน้าตรวจรูปภาพว่าภาพนั้นเป็น truecolor หรือไม่ รูปภาพที่จะเป็น truecolor อาจจะต้องถูกสร้างด้วยฟังก์ชัน imagecreatetruecolor() ซึ่งเป็นการสร้างรูปภาพอีกแบบโดยใช้ truecolor เป็นหลัก ซึ่งฟังก์ชัน imageustruecolor() เมื่อมีการตรวจสอบแล้วพบว่า ไม่ใช่ ก็จะคืนค่า เป็น false และในทางกลับกัน หากพบว่าเป็น truecolor ก็จะคืนค่าเป็น true น่ะครับ
รูปแบบ syntax
imageistruecolor (resource $image ): bool
โค้ดตัวอย่างดังนี้
<?php
// $im is an image instance
// Check if image is a true color image or not
if(!imageistruecolor($im))
{
// Create a new true color image instance
$tc = imagecreatetruecolor(imagesx($im), imagesy($im));
// Copy over the pixels
imagecopy($tc, $im, 0, 0, 0, 0, imagesx($im), imagesy($im));
imagedestroy($im);
$im = $tc;
$tc = NULL;
// OR use imagepalettetotruecolor()
}
// Continue working with image instance
?>
ฟังก์ชันนี้เป็นเพียงฟังชั่นที่ใช้ในการตรวจรูปภาพเท่านั้นและคืนค่าเป็น true หรือ false หลายๆคนอาจจะสงสัยเรื่อง สีจริงหรือ true color เพื่อเข้าใจขึ้น สามารถศึกษาเพิ่มเรื่องฟังก์ชัน imagecreatetruecolor() สร้างภาพสีจริงใหม่(true color) และฟังก์ชัน imagepalettetotruecolor() แปลงภาพจาก palette เป็นสีจริง(true color) น่ะครับ หวังว่าจะสามารถนำไปประยุกต์ต่อได้น่ะครับ