imagecolormatch

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>

gd_info

getimagesize

getimagesizefromstring

image_type_to_extension

image_type_to_mime_type

imageaffine

imageaffinematrixconcat

imageaffinematrixget

imagealphablending

imageantialias

imagearc

imageavif

imagebmp

imagechar

imagecharup

imagecolorallocate

imagecolorallocatealpha

imagecolorat

imagecolorclosest

imagecolorclosestalpha

imagecolorclosesthwb

imagecolordeallocate

imagecolorexact

imagecolorexactalpha

imagecolorresolve

imagecolorresolvealpha

imagecolorset

imagecolorsforindex

imagecolorstotal

imagecolortransparent

imageconvolution

imagecopy

imagecopymerge

imagecopymergegray

imagecopyresampled

imagecopyresized

imagecreate

imagecreatefromavif

imagecreatefrombmp

imagecreatefromgif

imagecreatefromjpeg

imagecreatefrompng

imagecreatefromstring

imagecreatefromtga

imagecreatefromwbmp

imagecreatefromwebp

imagecreatefromxbm

imagecreatefromxpm

imagecreatetruecolor

imagecrop

imagecropauto

imagedashedline

imagedestroy

imageellipse

imagefill

imagefilledarc

imagefilledellipse

imagefilledpolygon

imagefilledrectangle

imagefilltoborder

imagefilter

imageflip

imagefontheight

imagefontwidth

imageftbbox

imagefttext

imagegammacorrect

imagegetclip

imagegetinterpolation

imagegif

imageinterlace

imageistruecolor

imagejpeg

imagelayereffect

imageline

imageloadfont

imageopenpolygon

imagepalettecopy

imagepalettetotruecolor

imagepng

imagepolygon

imagerectangle

imageresolution

imagerotate

imagesavealpha

imagescale

imagesetbrush

imagesetclip

imagesetinterpolation

imagesetpixel

imagesetstyle

imagesetthickness

imagesettile

imagestring

imagestringup

imagesx

imagesy

imagetruecolortopalette

imagettfbbox

imagettftext

imagetypes

imagewbmp

imagewebp

imagexbm

iptcembed

iptcparse

HomeMenu