PHP: imagecolormatch - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imagecolorresolve imagecolorexactalpha

Last updated: Fri, 26 Jan 2007

view this page in

# imagecolormatch

(PHP 4 >= 4.3.0, PHP 5)

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

## Описание

bool imagecolormatch ( resource image1, resource image2 )

Внимание
К настоящему времени эта функция еще не была документирована; для ознакомления доступен только список аргументов.

## Список параметров

`image1`

  A truecolor image link resource

`image2`

  A palette image link resource pointing to an image that has the same size as `image1`

## Возвращаемые значения

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки.

## Примечания

> Замечание: Эта функция доступна только в том случае, если PHP был скомпилирован со встроенной библиотекой GD.

> Замечание: Эта функция нуждается в GD версии 2.0.1 или выше.

## Смотрите также

imagecreatetruecolor()

add a note User Contributed Notes
imagecolormatch
albriNOght at anSPAMre dot net
12-Dec-2005 09:22
`This function appears to work by changing the values of the colors of the paletted image -- no good if you're trying to force the resultant image to stick with certain pre-defined color values.`
Samantha
08-Feb-2004 07:14
`This function is a godsend! It works exactly as documented.
I'm working on an application where I need to take a transparent GIF, matte the GIF on a user defined background color, and finally scale the GIF based on a user defined %.
The only way I could get this to work so that the final image was high quality, ie: no jagged edges, and a smooth scale, was to convert the GIF to a JPG, and then copy the JPG into a new GIF image like this:
// open transparent gif
$GIFimg = imagecreatefromgif($file_path);
// create jpg image
$JPGimg = imagecreatetruecolor($width, $height);
// copy GIF to JPG
imagecopy($JPGimg, $GIFimg, 0, 0, 0, 0, $width, $height);
// create a true color image
$JPGscaled = imagecreatetruecolor($n_width, $n_height);
// scale the new JPG using the truecolor image
imagecopyresampled($JPGscaled, $JPGimg, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// create final GIF image
$GIFfinal = imagecreate($n_width, $n_height);
// copy the scaled JPG back to a GIF
imagecopymerge($GIFfinal, $JPGscaled, 0, 0, 0, 0, $n_width, $n_height, 100);
This worked great except the final step, copying the JPG to a GIF. If the JPG had too many colors, the function would index the colors to make it a palette image. So what would end up happening is the final image contained INCORRECT colors.
Adding this one line at the bottom of the code fixed everything.
imagecolormatch($JPGscaled, $GIFfinal);
I hope this helps anyone who is converting images back and forth and dealing with palette issues and color correction. Also, be aware that the above code is a sample and will not work by copying and pasting.`
add a note
imagecolorresolve imagecolorexactalpha

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST