HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

imagecolormatch

Description

The imagecolormatch of Image for PHP makes the colors of the palette version of an image more closely match the true color version.

Syntax

imagecolormatch(
    GdImage $image1,
    GdImage $image2
): bool

Parameters

image1

A truecolor image object.

image2

A palette image object pointing to an image that has the same size as image1.

Return

Returns true on success or false on failure.

Examples

1 · return

<?

$width = 100;
$height = 100;
$image1 = imagecreatetruecolor($width, $height);

$image2 = imagecreate($width, $height);

$red = 255;
$green = 255;
$blue = 255;
imagecolorallocate($image2, $red, $green, $blue);

$return = imagecolormatch($image1, $image2);

var_export($return);
true

2 · base64

<?

$width = 100;
$height = 100;
$image1 = imagecreatetruecolor($width, $height);

ob_start();

    imagepng($image1);

$output1 = ob_get_clean();

$image2 = imagecreate($width, $height);

$red = 255;
$green = 255;
$blue = 255;
imagecolorallocate($image2, $red, $green, $blue);

ob_start();

    imagepng($image2);

$output2 = ob_get_clean();

imagecolormatch($image1, $image2);

ob_start();

    imagepng($image2);

$output3 = ob_get_clean();

echo '<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,' . base64_encode($output1) . '"><br>
    <img src="data:image/png;base64,' . base64_encode($output2) . '"><br>
    <img src="data:image/png;base64,' . base64_encode($output3) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAANElEQVR4nO3BAQ0AAADCoPdPbQ43oAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfgx1lAABqFDyOQAAAABJRU5ErkJggg=="><br>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAAA1BMVEX///+nxBvIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAFElEQVQ4jWNgGAWjYBSMglFATwAABXgAAfmlXscAAAAASUVORK5CYII="><br>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAAA1BMVEUAAACnej3aAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAFElEQVQ4jWNgGAWjYBSMglFATwAABXgAAfmlXscAAAAASUVORK5CYII=">
</body>
</html>