php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #59420 invalid setimageformat!
Submitted: 2010-09-15 03:42 UTC Modified: 2010-10-03 05:01 UTC
From: hi dot laowang at gmail dot com Assigned: vito (profile)
Status: Closed Package: gmagick (PECL)
PHP Version: 5.3.2 OS: linux
Private report: No CVE-ID: None
 [2010-09-15 03:42 UTC] hi dot laowang at gmail dot com
Description:
------------
when I change gif animated picture from gif to png.
no change happened.

Reproduce code:
---------------
        $image_handle = new Gmagick();
        $image_handle->readImageBlob($file);

        $image_handle->setimageformat('png');

        $image_handle->getImageBlob();

Expected result:
----------------
png

Actual result:
--------------
gif

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-15 06:05 UTC] hi dot laowang at gmail dot com
$first->addImage($second);
$first->setimageformat('gif');

can't get gif animated picture
 [2010-09-19 12:29 UTC] vito@php.net
For the description at 2010-09-15 07:42 UTC, you will be able to get to echo the image as a PNG by doing:

...
$image->setimageformat('png');
header("Content-Type: image/png");
echo $image;

Make sure you have the decode delegate for PNG available. If you write() an image that is read from a blob that is originally GIF, but changed to PNG via setImageFormat(), you should get multiple PNG files corresponding to the number of images in the GIF. For example, if example.gif is a 2 image GIF, the following:

$file = "example.gif";
$firstHandle = new Gmagick($file);
$firstBlob = $firstHandle->getImageBlob();
$secondHandle = new Gmagick();
$secondHandle->readImageBlob($firstBlob);
$secondHandle->setimageformat('png');
$secondBlob = $secondHandle->getImageBlob();
$thirdHandle = new Gmagick();
$thirdHandle->readImageBlob($secondBlob);
$thirdHandle->write('example.png');

will yield:

example.png.0
example.png.1
 [2010-10-03 05:01 UTC] vito@php.net
Thank you for taking the time to write to us, but this is not
a bug.

As for the additional comment on 2010-09-15 10:05 UTC; as per GraphicsMagick documentation, addImage() adds the specified image at the current image location. You'll need to use nextImage() to create the image location and previousImage() to return to the location where you'll want the GIF creation to occur. If you have many images, it is important to manage the wand location properly. Here's an example:

$first = new Gmagick("example.0.png");
$first->setImageformat("gif");
$first->setImageDelay(100);
$second = new Gmagick ("example.1.png");
$first->nextImage();
$first->addImage($second);
$first->previousImage();
$first->write('example.gif');
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC