note 27434 deleted from function.imagegif by danbrown

From: Date: Tue, 09 Jun 2009 13:17:52 +0000
Subject: note 27434 deleted from function.imagegif by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156604@lists.php.net to get a copy of this message
Note Submitter: tom et lenderlab dit com ---- The rgb2gif utility included in giflib can be used for fast and easy gif output with any version of GD http://ietpd1.sowi.uni-mainz.de/cgi-bin/man2html?rgb2gif use either the rgboutput or the rgboutput_truecolor functions, depending on your GD version/style of image you're working with: <? $x=40; $y=40; //make a simple image with some text $im = imagecreate($x, $y); $bg = imagecolorallocate($im, 0,0,0); imagefill($im, 0,0, $bg); $red=imagecolorallocate($im, 255, 0, 0); imagestring($im, 1, 2, 8, "testing", $red); //output the 24 bit rgb-formatted image to file $f = fopen("image.rgb", "w"); fwrite($f, rgboutput($im)); imagedestroy($im); //load that file into rgb2gif and capture the output $status = rgb2gif -1 -s $x $y image.rgb; $f = fopen("test.gif", "w"); fwrite($f, $status); function rgboutput($im) { $x = imagesx($im); $y = imagesy($im); $output=""; for($i=0;$i<$y;$i++) { for($j=0;$j<$x;$j++) { $c=ImageColorAt($im, $j, $i); $c = imagecolorsforindex($im, $c); $c = array_map("chr", $c); $output.=$c['red'].$c['green'].$c['blue']; } } return $output; } function rgboutput_truecolor($im) { $x = imagesx($im); $y = imagesy($im); $output=""; for($i=0;$i<$y;$i++) { for($j=0;$j<$x;$j++) { $rgb=ImageColorAt($im, $j, $i); $r = chr(($rgb >> 16) & 0xFF); $g = chr(($rgb >> 8) & 0xFF); $b = chr($rgb & 0xFF); $output.=$r.$g.$b; } } return $output; } ?><img src="test.gif">

« previous php.notes (#156604) next »