ID:               14820
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: Any
 PHP Version:      4.1.1
 New Comment:

To implement such a function would require PHP to go through every
single pixel of the image, which would be tremendously slow. There is
just no practical way to implement this feature, sorry.


Previous Comments:
------------------------------------------------------------------------

[2002-06-28 05:42:59] [EMAIL PROTECTED]

reclassified.

------------------------------------------------------------------------

[2002-01-03 04:05:32] [EMAIL PROTECTED]

ImageColorResolve et al are really cool, but SOMETIMES you 
*need* the color you want, and they just won't cut it.

So you want to deallocate the least-used color, and then 
allocate the one you really want.

Alas, the only way to do that (as far as I can figger) is 
this:

$colorcount = array();
for ($x = 0; $x < $width; $x++){
        for ($y = 0; $y < $height; $y++){
                $colorindex = imagecolorat($jpg, $x, $y);
                if (!isset($colorcount[$colorindex])){
                        $colorcount[$colorindex] = 1;
                }
                else{
                        $colorcount[$colorindex]++;
                }
        }
}
asort($colorcount);
reset($colorcount);

$black = imagecolorexact($jpg, 0, 0, 0);
if ($black == -1){
        $goner = key($colorcount);
        $rgb = imagecolorsforindex($jpg, $goner);
        #error_log("Need black: About to kill $goner ($rgb[red], 
$rgb[green], $rgb[blue]) which was only used in 
$colorcount[$goner] pixels", 0);
        unset($colorcount[$goner]);
        imagecolordeallocate($jpg, $goner);
        $black = imagecolorallocate($jpg, 0, 0, 0);
}
if ($black == -1){
        $black = imagecolorresolve($jpg, 0, 0, 0);
        #error_log("Damn!  STILL couldn't allocate the color!", 
0);
}


Ugly, ain't it :-)

Anyway, if GD has any internal structures of a histogram 
nature, that one could use for a function matching this 
documentation:

int ImageColorLeastUsed(int img)
Returns a color index of the least-used color in the image.
Suitable for ImageDeallocate() when you really need a color 
that is not in the image.

Also handy would be something like:
array ImageColorMostContrasty(int img)
Returns an a array of 'red', 'green', 'blue' at a maxium 
distance from all other colors currently in the image.

I have no clue which color-distance algorithm I would 
actually want here.  But it would be nice for adding 
overlays to existing images that come from a random source.

If you want some idea of what I'm talking about:
http://chatmusic.com/maplocater.htm

The latitude/longitude lines and the red circles are being 
pulled from a database and overlaid in real-time.  However, 
somebody might upload a map with lots of red and black in 
it, and then I've got un-usable images.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=14820&edit=1

Reply via email to