PHP: how to express "near white" as a color?

gd, php, rgb

Solution

$color = imagecolorat($img, $x, $top);
$color = array(
    'red'   => ($color >> 16) & 0xFF,
    'green' => ($color >>  8) & 0xFF,
    'blue'  => ($color >>  0) & 0xFF,
);
if ($color['red']   >= 0xFD
 && $color['green'] >= 0xFD
 && $color['blue']  >= 0xFD) {
    //sets where the top part of the image is trimmed
}

For a description of the operators used, please read:

- PHP - Two unusual operators used together to get image pixel color, please explain

Problem

I have a function for trimming white areas around images that works something like ``` if(imagecolorat($img, $x, $top) != 0xFFFFFF) { //sets where the top part of the image is trimmed } ``` The problem is some images have an occasional stray pixel that is so near white that it's unnoticeable but screws up the cropping because it's not exactly 0xFFFFFF but 0xFFFEFF or something. How could I rewrite the above statement so that it evaluates true for those near white images, say down to 0xFDFDFD, obviously without testing for ever possible value.

Original source

Related problems