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
a>
Edit -- https://master
.php.net/note/edit/76032
Del: integrated -- h
ttps://master.php.net/note/delete/76032/integrated
Del: useless -- http
s://master.php.net/note/delete/76032/useless
Del: bad code -- htt
ps://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 -- http
s://master.php.net/note/delete/76032/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/76032
Reject -- https://mast
er.php.net/note/reject/76032
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|