GD colorClosest()
syntax: |
gd.colorClosest(red, green, blue) |
where: |
red - Red value, from 0 to 255
green - Green value, from 0 to 255
blue - Blue value, from 0 to 255
|
return: |
number - index of the closest color to the one supplied.
|
description: |
This method searches through the color table and finds the closest color to the one supplied. The algorithm uses Euclidian distance to calculate closeness. This function is most useful when unable to allocate a new color, and the closest must be used instead.
|
see: |
#link <gd>, GD colorAllocate()
|
example: |
/* Attempt to allocate a specific color, * but if unable to (the image * has the maximum number of colors), * then attempt to find the closest * color as a suitable replacement */ var gd = GD.fromGif("test.gif"); var index; if( -1 == (index = gd.colorAllocate(234,12,107)) ) index = gd.colorClosest(234,12,107); |