suche nach in der

imagecolorstotal> <imagecolorset
Last updated: Fri, 18 May 2012

view this page in

imagecolorsforindex

(PHP 4, PHP 5)

imagecolorsforindex Ermittelt die Farbwerte einer angegebenen Farb-Palette

Beschreibung:

array imagecolorsforindex ( resource $im , int $index )

Gibt ein assoziatives Array mit Rot-, Grün- und Blau-Werten zurück, die die Werte des Farb-Paletten-Index von im darstellen.

Siehe auch imagecolorat() und imagecolorexact().



add a note add a note User Contributed Notes
imagecolorsforindex
adspeed.com
24-Aug-2005 01:05
To correct m4551 at abasoft dot it example:

ImageTrueColorToPalette($im,1,$t);

might give less colors than $t, so the for loop should call "$i<ImageColorsTotal($im)" instead of "$i<$t" just to be sure, or you'll get the warning: Color index [0-9] out of range
strozek(a)deas()harvard()edu
25-Jun-2004 10:32
Regarding m4551's method of conversion -- the actual CCIR-approved RGB-to-grayscale conversion is as follows:

grayscale component = 0.2125*R + 0.7154*G + 0.0721*B

(cf. CCIR Recommendation 709 for modern monitors)
m4551 at abasoft dot it
23-Apr-2004 06:23
here's a function to greyscale an image even from a truecolor source (jpeg or png).

slightly poor quality, but very fast...

function imagegreyscale(&$img, $dither=1) {   
    if (!($t = imagecolorstotal($img))) {
        $t = 256;
        imagetruecolortopalette($img, $dither, $t);   
    }
    for ($c = 0; $c < $t; $c++) {   
        $col = imagecolorsforindex($img, $c);
        $min = min($col['red'],$col['green'],$col['blue']);
        $max = max($col['red'],$col['green'],$col['blue']);
        $i = ($max+$min)/2;
        imagecolorset($img, $c, $i, $i, $i);
    }
}

imagecolorstotal> <imagecolorset
Last updated: Fri, 18 May 2012