PHP | imagecolormatch()函数

这个 imagecolormatch() 函数是PHP中的一个内置函数,用于使图像调色板版本的颜色更接近真彩色版本。此函数在成功时返回true,失败时返回false。

null

语法:

bool imagecolormatch ( $image1, $image2 )

参数: 该函数接受两个参数,如下所述:

  • $image1: 它由一个图像创建函数返回,例如imagecreatetruecolor()。它用于创建图像的大小。
  • $image2: 调色板图像将资源链接到与image1大小相同的图像。

返回值: 此函数在成功时返回True,失败时返回False。

下面的程序说明了 imagecolormatch() PHP中的函数:

项目1:

<?php
// Setup the true color and palette images
$image1 = imagecreatefrompng(
// Palette image created with same size as image1
$image2 = imagecreate(imagesx( $image1 ), imagesy( $image1 ));
// Add some colors to $image2
$color = Array();
$color [] = imagecolorallocate( $image2 , 152, 0, 231);
$color [] = imagecolorallocate( $image2 , 140, 10, 104);
$color [] = imagecolorallocate( $image2 , 32, 109, 155);
$color [] = imagecolorallocate( $image2 , 184,163, 15);
// Match these colors with the true color image
echo imagecolormatch( $image1 , $image2 );
// Free from memory
imagedestroy( $image1 );
imagedestroy( $image2 );
?>


输出:

1

项目2:

<?php
// Setup the true color and palette images
$image1 = imagecreatefrompng(
// Palette image created with same size as image1
$image2 = imagecreate(imagesx( $image1 ), imagesy( $image1 ));
// Add some colors to $image2
$color = Array(
$color [] = imagecolorallocate( $image2 , 25, 136, 147),
$color [] = imagecolorallocate( $image2 , 230, 100, 204),
$color [] = imagecolorallocate( $image2 , 21, 100, 155),
$color [] = imagecolorallocate( $image2 , 41, 63, 234)
);
// Match these colors with the true color image
echo imagecolormatch( $image1 , $image2 );
// Free from memory
imagedestroy( $image1 );
imagedestroy( $image2 );
?>


输出:

1

相关文章:

参考: http://php.net/manual/en/function.imagecolormatch.php

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享