|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2017-01-24 13:10 UTC] fortin81 at gmail dot com
  [2017-01-24 13:22 UTC] cmb@php.net
 
-Status:      Open
+Status:      Duplicate
-Assigned To:
+Assigned To: cmb
  [2017-01-24 13:22 UTC] cmb@php.net
  [2017-02-27 15:54 UTC] greg at gregoriol dot net
  [2017-02-27 16:08 UTC] cmb@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Wed Oct 22 16:00:01 2025 UTC | 
Description: ------------ In a script, we are using PHP and GD function imagecreatefromstring to read image files and check if they are valid images. We don't know at this point if it is a jpeg/png/..., it could be a base64 encoded string too. This gave us a return value of true if the image was valid, and false if the image was invalid, which was grat. Now, the same code PHP gives a Fatal Error, and we can't find a way to implement the same check as before... We don't really care about the warnings GD emits: we know some of the files will be "invalid". But we really care about the bool(false) result as this was our way to check the file. NB: invalid images could be Apple crushed PNGs like in the test script file. Test script: --------------- <?php $b = file_get_contents('https://www.gregoriol.net/tmp/AppIcon.png'); $r = imagecreatefromstring($b); var_dump($r); Expected result: ---------------- $ php -v PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies $ php test-imagecreatefromstring.php PHP Unknown error: imagecreatefromstring(): gd-png: fatal libpng error: CgBI: unknown critical chunk in Unknown on line 0 PHP Parse error: imagecreatefromstring(): gd-png error: setjmp returns error condition 1 in test-imagecreatefromstring.php on line 5 PHP Warning: imagecreatefromstring(): Passed data is not in 'PNG' format in test-imagecreatefromstring.php on line 5 PHP Warning: imagecreatefromstring(): Couldn't create GD Image Stream out of Data in test-imagecreatefromstring.php on line 5 bool(false) Actual result: -------------- $ php -v PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.13-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies $ php test-imagecreatefromstring.php PHP Fatal error: imagecreatefromstring(): gd-png: fatal libpng error: CgBI: unknown critical chunk in test-imagecreatefromstring.php on line 5