note 76032 added to function.imagecolorset
| From: | wolfgang_ling at rc dot europe dot yahoo-eu1 dot akadns dot net | Date: | Wed, 27 Jun 2007 09:10:22 +0000 |
| Subject: | note 76032 added to function.imagecolorset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128019@lists.php.net to get a copy of this message | ||
C'est la même fonction, mais en mettant imagecolorstotal hors de la boucle, on évite de
le recalculer a chaque fois (comme le nombre de couleurs de l'image n'est pas censé
changé, il vaut mieux ne faire le test qu'une fois).
<?php
function imagetograyscale($im)
{
if (imageistruecolor($im)) {
imagetruecolortopalette($im, false, 256);
}
$total = imagecolorstotal($im);
for ($c = 0; $c < $total; $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);
}
}
?>
----
Server IP: 195.221.21.36
Probable Submitter: 194.214.24.100 (proxied: 193.51.97.112)
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorset.php
Edit -- https://master.php.net/note/edit/76032
Del: integrated -- https://master.php.net/note/delete/76032/integrated
Del: useless -- https://master.php.net/note/delete/76032/useless
Del: bad code -- https://master.php.net/note/delete/76032/bad+code
Del: spam -- https://master.php.net/note/delete/76032/spam
Del: non-english -- https://master.php.net/note/delete/76032/non-english
Del: in docs -- https://master.php.net/note/delete/76032/in+docs
Del: other reasons-- https://master.php.net/note/delete/76032
Reject -- https://master.php.net/note/reject/76032
Search -- https://master.php.net/manage/user-notes.php