Voting

: four minus three?
(Example: nine)

The Note You're Voting On

moxleystratton.com
18 years ago
If you want to convert a Color image to Grayscale without creating a blotchy image, use this color calculation:
<?php
function imagetograyscale($im)
{
if (
imageistruecolor($im)) {
imagetruecolortopalette($im, false, 256);
}

for (
$c = 0; $c < imagecolorstotal($im); $c++) {
$col = imagecolorsforindex($im, $c);
$gray = round(0.299 * $col['red'] + 0.587 * $col['green'] + 0.114 * $col['blue']);
imagecolorset($im, $c, $gray, $gray, $gray);
}
}
?>

<< Back to user notes page

To Top