note 66766 added to function.imagetruecolortopalette

From: Date: Sun, 28 May 2006 16:51:53 +0000
Subject: note 66766 added to function.imagetruecolortopalette
Groups: php.notes 
Request: Send a blank email to php-notes+get-112451@lists.php.net to get a copy of this message
If You know which palette to use (e.g. 255 colors greyscale) You may achieve better results using the following way: 1. Create new image 2. Apply palette 3. imagecopy() the content This is especially helpful if you created a greyscale picture in trucolor-mode (to use antialiasing for example) but need to send it as palette (to use transparency in Internet Explorer). The following example will *not* create great results from "real" truecolor images but works well on grey truecolor images: <?PHP function imageTruecolorToGrayscale(&$image) { $copy = $image; $dx = imagesx($image); $dy = imagesy($image); $image = imagecreate($dx, $dy); // 254 Colors + 1 reserved for transparency $transparency = imagecolorallocate($image, 0, 255, 0); $max = 255; $dd = 254; for ($i=0; $i<$dd; $i++) { $val = round($max * $i / ($dd-1)); imagecolorallocate($image, $val, $val, $val); } imagecopy($image, $copy, 0, 0, 0, 0, $dx, $dy); imagedestroy($copy); return $transparency; } ?> ---- Server IP: 217.160.72.57 Probable Submitter: 84.57.53.182 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.imagetruecolortopalette.php Edit -- http://master.php.net/note/edit/66766 Del: integrated -- http://master.php.net/note/delete/66766/integrated Del: useless -- http://master.php.net/note/delete/66766/useless Del: bad code -- http://master.php.net/note/delete/66766/bad+code Del: spam -- http://master.php.net/note/delete/66766/spam Del: non-english -- http://master.php.net/note/delete/66766/non-english Del: in docs -- http://master.php.net/note/delete/66766/in+docs Del: other reasons-- http://master.php.net/note/delete/66766 Reject -- http://master.php.net/note/reject/66766 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112451) next »