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

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


ฟังก์ชัน imagecolormatch() ปรับสีของ palette image ให้ใกล้เคียง true color image มากขึ้น

ไวยากรณ์

bool imagecolormatch (img1, img2)

พารามิเตอร์

  • img1: True color image จาก imagecreatetruecolor()
  • img2: Palette image resource ขนาดเท่ากับ img1

คืนค่า

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

ตัวอย่าง

<?php 
$img1 = imagecreatefrompng('https://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

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

<?php 
$img1 = imagecreatefrompng('https://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