PHP 中的 imagecolormatch() 函数
phpserver side programmingprogramming更新于 2025/7/6 4:52:17
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

