php.net |  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
Votes:2
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-02-25 13:39 UTC] maximilian dot bloch at gmail dot com
Description:
------------
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:

<?php
  $image = new Gmagick();
  exec("gm convert label:test png:- > /tmp/test.png");
  $image->read('/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:
---------------
<?php
  //$image = new Imagick(); // works
  $image = new Gmagick();
  $cmd = "gm convert label:test png:-";
  $handle = popen($cmd, 'r');
  $image->readImageFile($handle);
  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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-25 23:54 UTC] danack@php.net
-Assigned To: +Assigned To: danack
 [2016-02-25 23:54 UTC] danack@php.net
I probably ought to have a look at this. It has been reported before a 'little' while ago. https://bugs.php.net/bug.php?id=62308

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:

<?php
  $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-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC