|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 20:00:01 2025 UTC |
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(); ?>