LonghornPHP 2026

Voting

: one plus one?
(Example: nine)

The Note You're Voting On

m4551 at abasoft dot it
22 years ago
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);
    }
}

<< Back to user notes page

To Top