note 119564 added to function.imagecreatefromgif

From: Date: Thu, 07 Jul 2016 14:13:17 +0000
Subject: note 119564 added to function.imagecreatefromgif
Groups: php.notes 
Request: Send a blank email to php-notes+get-205915@lists.php.net to get a copy of this message
I hate created an improved version of frank at huddler dot com's is_ani function, which keeps score even between hunks. Hope this helps! /** * Check if the provided file is an animated gif. * * @param string $fileName * @return bool */ function isAnimatedGif($fileName) { $fh = fopen($fileName, 'rb'); if (!$fh) { return false; } $totalCount = 0; $chunk = ''; // An animated gif contains multiple "frames", with each frame having a header made up of: // * a static 4-byte sequence (\x00\x21\xF9\x04) // * 4 variable bytes // * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?) // We read through the file until we reach the end of it, or we've found at least 2 frame headers. while (!feof($fh) && $totalCount < 2) { // Read 100kb at a time and append it to the remaining chunk. $chunk .= fread($fh, 1024 * 100); $count = preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches); $totalCount += $count; // Execute this block only if we found at least one match, // and if we did not reach the maximum number of matches needed. if ($count > 0 && $totalCount < 2) { // Get the last full expression match. $lastMatch = end($matches[0]); // Get the string after the last match. $end = strrpos($chunk, $lastMatch) + strlen($lastMatch); $chunk = substr($chunk, $end); } } fclose($fh); return $totalCount > 1; } ---- Server IP: 72.52.91.14 Probable Submitter: 89.40.184.35 ---- Manual Page -- http://php.net/manual/en/function.imagecreatefromgif.php Edit -- https://master.php.net/note/edit/119564 Del: integrated -- https://master.php.net/note/delete/119564/integrated Del: useless -- https://master.php.net/note/delete/119564/useless Del: bad code -- https://master.php.net/note/delete/119564/bad+code Del: spam -- https://master.php.net/note/delete/119564/spam Del: non-english -- https://master.php.net/note/delete/119564/non-english Del: in docs -- https://master.php.net/note/delete/119564/in+docs Del: other reasons-- https://master.php.net/note/delete/119564 Reject -- https://master.php.net/note/reject/119564 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205915) next »