note 75727 added to function.imagecolorallocate

From: Date: Wed, 13 Jun 2007 15:15:46 +0000
Subject: note 75727 added to function.imagecolorallocate
Groups: php.notes 
Request: Send a blank email to php-notes+get-127448@lists.php.net to get a copy of this message
Another solution to color limitation issues when creating gradients. This file takes width (px) and left and right colors (hex) and makes a gradient while only allocating 250 colors. <?php $leftR = hexdec(substr($_GET["left"],0,2)); $leftG = hexdec(substr($_GET["left"],2,2)); $leftB = hexdec(substr($_GET["left"],4,2)); $rightR = hexdec(substr($_GET["right"],0,2)); $rightG = hexdec(substr($_GET["right"],2,2)); $rightB = hexdec(substr($_GET["right"],4,2)); $image=imagecreate($_GET["width"],1); for($i=0;$i<250;$i++) { $colorset[$i] = imagecolorallocate($image, $leftR + ($i*(($rightR-$leftR)/250)), $leftG + ($i*(($rightG-$leftG)/250)), $leftB + ($i*(($rightB-$leftB)/250))); } for($i=0;$i<($_GET["width"]);$i++) { imagesetpixel ($image, $i, 0, $colorset[(int)($i/($_GET["width"]/250))] ); } header("Content-type: image/png"); imagepng($image); imagedestroy($image); ?> example: gradient.php?width=640&left=000000&right=FF0000 Makes a 640px-wide image that fades from black to red. ---- Server IP: 64.71.164.2 Probable Submitter: 63.170.191.2 ---- Manual Page -- http://www.php.net/manual/en/function.imagecolorallocate.php Edit -- https://master.php.net/note/edit/75727 Del: integrated -- https://master.php.net/note/delete/75727/integrated Del: useless -- https://master.php.net/note/delete/75727/useless Del: bad code -- https://master.php.net/note/delete/75727/bad+code Del: spam -- https://master.php.net/note/delete/75727/spam Del: non-english -- https://master.php.net/note/delete/75727/non-english Del: in docs -- https://master.php.net/note/delete/75727/in+docs Del: other reasons-- https://master.php.net/note/delete/75727 Reject -- https://master.php.net/note/reject/75727 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127448) next »