PHP imagecolormatch - Makes the colors in the palette version of an image more closely match the true color version

PHP 图像处理PHP Image Processing

imagecolormatch — Makes the colors in the palette version of an image more closely match the true color version.

Syntax

bool imagecolormatch ( resource $image1 , resource $image2 )

Makes the colors in the palette version of an image more closely match the true color version.

Note:This function is only available in PHP versions compiled with the bundled GD library.

Note:This function requires GD 2.0.1 or higher (recommended 2.0.28 or higher).

Parameters

  • image1True color image link resource.
  • image2Must be a palette image, and must have the same size as image1.

Return Values

Returns TRUE on success, or FALSE on failure.

Examples

<?php
// 创建真彩色图像和调色板图像
$im1 = imagecreatefrompng('example-logo.png');
$im2 = imagecreate(imagesx($im1), imagesy($im1));

// 向 $im2 添加一些颜色
$colors   = Array();
$colors[] = imagecolorallocate($im2, 255, 36, 74);
$colors[] = imagecolorallocate($im2, 40, 0, 240);
$colors[] = imagecolorallocate($im2, 82, 100, 255);
$colors[] = imagecolorallocate($im2, 84, 63, 44);

// 把这些颜色与真彩色图像进行匹配
imagecolormatch($im1, $im2);

// 从内存中释放
imagedestroy($im1);
imagedestroy($im2);
?>

Related Articles

  • imagecreatetruecolor()Create a new true color image.

PHP 图像处理PHP Image Processing

Other Extensions