PHP 中的 imagecolormatch() 函数
imagecolormatch() 函数将调色板版本图的色彩更接近真彩色版本
语法
bool imagecolormatch ( img1, img2 )
参数
img1:使用 imagecreatetruecolor() 函数创建图像。
img2:一个指向图像的调色板图像链接资源。此图像与 img1 尺寸相同。
返回值
成功时,imagecolormatch() 函数返回 TRUE,失败时返回 FALSE。
示例
以下是一个示例
<?php
$img1 = imagecreatefrompng('https://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('https://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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP