note 41841 added to function.imagecolorset
| From: | m4551atabasoftdotit at rn2 dot php dot net | Date: | Fri, 23 Apr 2004 13:19:41 +0000 |
| Subject: | note 41841 added to function.imagecolorset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68664@lists.php.net to get a copy of this message | ||
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);
}
}
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorset.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41841
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41841&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41841&report=yes
Search -- http://master.php.net/manage/user-notes.php