ฟังก์ชัน imagecolormatch() สร้างสีของเวอร์ชันจานสีของรูปภาพให้ใกล้เคียงกับเวอร์ชันสีจริงมากขึ้น
ไวยากรณ์
bool imagecolormatch ( img1, img2 )
พารามิเตอร์
-
img1 :สร้างภาพด้วยฟังก์ชัน imagecreatetruecolor()
-
img2 :ทรัพยากรลิงก์รูปภาพจานสีที่ชี้ไปที่รูปภาพ ภาพนี้มีขนาดเท่ากับ img1
คืนสินค้า
ฟังก์ชัน imagecolormatch() ส่งคืนค่า TRUE เมื่อสำเร็จ หรือ FALSE เมื่อล้มเหลว
ตัวอย่าง
ต่อไปนี้เป็นตัวอย่าง
<?php
$img1 = imagecreatefrompng('http://www.tutorialspoint.com/images/Swift.png');
$img2 = imagecreate(imagesx($img1), imagesy($img1));
$color = Array();
$color[] = imagecolorallocate($img2, 110, 40, 180);
$color[] = imagecolorallocate($img2, 90, 10, 90);
$color[] = imagecolorallocate($img2, 66, 170, 110);
$color[] = imagecolorallocate($img2, 130,90, 70);
echo imagecolormatch($img1, $img2);
imagedestroy($img1);
imagedestroy($img2);
?> ผลลัพธ์
ต่อไปนี้เป็นผลลัพธ์:
1
ตัวอย่าง
มาดูตัวอย่างกันต่อ
<?php
$img1 = imagecreatefrompng('http://www.tutorialspoint.com/images/tp-logo-diamond.png');
$img2 = imagecreate(imagesx($img1), imagesy($img1));
$color = Array();
$color[] = imagecolorallocate($img2, 10, 1, 20);
$color[] = imagecolorallocate($img2, 40, 30, 10);
$color[] = imagecolorallocate($img2, 15, 100, 50);
$color[] = imagecolorallocate($img2, 70, 20, 30);
echo imagecolormatch($img1, $img2);
imagedestroy($img1);
imagedestroy($img2);
?> ผลลัพธ์
ต่อไปนี้เป็นผลลัพธ์:
1