note 126300 added to function.imagecreatefrompng

From: Date: Mon, 02 Aug 2021 07:58:26 +0000
Subject: note 126300 added to function.imagecreatefrompng
Groups: php.notes 
Request: Send a blank email to php-notes+get-216714@lists.php.net to get a copy of this message
Because gd and imagick do not support animated PNG (at this moment), i wrote a simple function to determine if given PNG is APNG or not. It does not validate PNG, only checks whenever "acTL" chunk appears before "IDAT" like the specification says: https://wiki.mozilla.org/APNG_Specification <?php function is_apng(string $filename): bool { $f = new \SplFileObject($filename, 'rb'); $header = $f->fread(8); if ($header !== "\x89PNG\r\n\x1A\n") { return false; } while (!$f->eof()) { $bytes = $f->fread(4); if (strlen($bytes) < 4) { return false; } $length = unpack('N', $bytes)[1]; $chunkname = $f->fread(4); switch ($chunkname) { case 'acTL': return true; case 'IDAT': return false; } $f->fseek($length + 4, SEEK_CUR); } return false; } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 2a03:5800:f0c5:c580:3cef:ff45:275c:4cf4) ---- Manual Page -- https://php.net/manual/en/function.imagecreatefrompng.php Edit -- https://main.php.net/note/edit/126300 Del: integrated -- https://main.php.net/note/delete/126300/integrated Del: useless -- https://main.php.net/note/delete/126300/useless Del: bad code -- https://main.php.net/note/delete/126300/bad+code Del: spam -- https://main.php.net/note/delete/126300/spam Del: non-english -- https://main.php.net/note/delete/126300/non-english Del: in docs -- https://main.php.net/note/delete/126300/in+docs Del: other reasons-- https://main.php.net/note/delete/126300 Reject -- https://main.php.net/note/reject/126300 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216714) next »