note 70280 added to function.imagecreatefromgif

From: Date: Tue, 10 Oct 2006 00:40:49 +0000
Subject: note 70280 added to function.imagecreatefromgif
Groups: php.notes 
Request: Send a blank email to php-notes+get-118332@lists.php.net to get a copy of this message
I wanted to find out if a GIF is Black & White or Color, but I didn't want to wait around for imagecreatefromgif() to parse a 200k file (about 1 second) to get the color map, so I wrote this function to get a list of all the colors in the GIF. Hope it is useful for you. <?php function getGIFColorMap($file) { $fp = fopen($file, 'r'); $buf = fread($fp, 1024); fclose($fp); // Calculate number of colors // buf[10] is the color info byte $color_byte = ord($buf[10]); $has_color_map = ($color_byte >> 7) & 1; $color_res = (($color_byte >> 4) & 7) + 1; $bits_per_pixel = ($color_byte & 7) + 1; $color_count = 1 << $bits_per_pixel; if (!$has_color_map) return null; // buf[13] is the beginning of the color map $color_map_index = 13; $map = array(); for ($i=0; $i < $color_count; $i++) { $index = $color_map_index + $i*3; $r = ord($buf[$index]); $g = ord($buf[$index + 1]); $b = ord($buf[$index + 2]); $map[$i] = array($r, $g, $b); } return $map; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 12.111.169.242 ---- Manual Page -- http://www.php.net/manual/en/function.imagecreatefromgif.php Edit -- https://master.php.net/note/edit/70280 Del: integrated -- https://master.php.net/note/delete/70280/integrated Del: useless -- https://master.php.net/note/delete/70280/useless Del: bad code -- https://master.php.net/note/delete/70280/bad+code Del: spam -- https://master.php.net/note/delete/70280/spam Del: non-english -- https://master.php.net/note/delete/70280/non-english Del: in docs -- https://master.php.net/note/delete/70280/in+docs Del: other reasons-- https://master.php.net/note/delete/70280 Reject -- https://master.php.net/note/reject/70280 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118332) next »