note 27434 added to function.imagegif

From: Date: Thu, 05 Dec 2002 19:08:19 +0000
Subject: note 27434 added to function.imagegif
Groups: php.notes 
Request: Send a blank email to php-notes+get-40390@lists.php.net to get a copy of this message
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"> -- http://www.php.net/manual/en/function.imagegif.php http://master.php.net/manage/user-notes.php?action=edit+27434 http://master.php.net/manage/user-notes.php?action=delete+27434 http://master.php.net/manage/user-notes.php?action=reject+27434

« previous php.notes (#40390) next »