|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71661 Gmagick::readImageFile() complains about improper image header
Submitted: 2016-02-25 13:39 UTC Modified: 2016-02-26 19:48 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:-1 (-100.0%)
From: maximilian dot bloch at gmail dot com Assigned: danack (profile)
Status: Assigned Package: gmagick (PECL)
PHP Version: 5.6.18 OS: Ubuntu 15.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: maximilian dot bloch at gmail dot com
New email:
PHP Version: OS:


 [2016-02-25 13:39 UTC] maximilian dot bloch at gmail dot com
It's me again ;-)

I am not able to get Gmagick to read a PNG-image from an open file descriptor via Gmagick::readImageFile(), as Gmagick throws a GmagickException:

  'Improper image header ()'

The image seems to be fine however. I can save the same image to file and Gmagick will not complain with the following workaround example:

  $image = new Gmagick();
  exec("gm convert label:test png:- > /tmp/test.png");
  header('Content-type: image/' . $image->getImageFormat());
  echo $image->getImageBlob();

Any way to fix the below test script or any idea for a better workaround than saving to file? OK, The file could be saved to shared memory, but I would like to avoid writing to file in general.

 - I am using gmagick-1.1.7RC3
 - Imagick works BTW

Test script:
  //$image = new Imagick(); // works
  $image = new Gmagick();
  $cmd = "gm convert label:test png:-";
  $handle = popen($cmd, 'r');
  header('Content-type: image/' . $image->getImageFormat());
  echo $image->getImageBlob();

Expected result:
Expected: A valid PNG image.

Actual result:
Fatal error: Uncaught exception 'GmagickException' with message 'Improper image header ()' in test.php:6 Stack trace: #0 test.php(6): Gmagick->readimagefile(Resource id #2) #1 {main} thrown in test.php on line 6


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-25 23:54 UTC]
-Assigned To: +Assigned To: danack
 [2016-02-25 23:54 UTC]
I probably ought to have a look at this. It has been reported before a 'little' while ago.

I have a suspicion that it may be just be broken in the underlying GraphicsMagick library, in which case there might not be a whole lot that Gmagick can do to make it work.
 [2016-02-26 19:48 UTC] maximilian dot bloch at gmail dot com
Thanks for the heads up danack. The mentioned duplicate bug report with its workaround seems to be a good solution and works for me:

  $image = new Gmagick();
  $cmd = "gm convert label:test png:-";
  $handle = popen($cmd, 'r');
  //$image->readImageFile($handle); // broken
  $image->readImageBlob(stream_get_contents($handle)); // workaround
  header('Content-type: image/' . $image->getImageFormat());
  echo $image->getImageBlob();
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 20:01:32 2024 UTC