PHP API and displaying animated gif's doesn't work?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hotzenplotz

PHP API and displaying animated gif's doesn't work?

Post by hotzenplotz »

hi, using php5 5.2.0, imagemagick 6.4.2 and imagick api 2.1.1. I'm using the following code:

$im=new Imagick("image.ext");
header('Content-type: image/type');
echo $im;

for displaying a JPEG-file or PNG-file this works fine, also for GIFs, but not for animated GIFs. imagick seems to load only the first frame. with function readImage nothing is changed. so, what can I do?

nico
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PHP API and displaying animated gif's doesn't work?

Post by anthony »

That is not the right way to export a image.

If you are using a API, which it looks like, you convert the image into a 'blob' that is the right format. If using command calls from PHP, you can have the command output the image in the format wanted using png:- or whatever.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
hotzenplotz

Re: PHP API and displaying animated gif's doesn't work?

Post by hotzenplotz »

ok, I understand, but after trying for a while, I don't get things to work with php-api. With

$image=get_file_contents("pic.gif");
header('Content...');
echo $image;

alls works fine, but not the imagick api. I tried

$image=new Imagick();
$image->readImage("pic.gif");
header('Content...');
echo $image->getImageBlob();

and tried also to add

foreach ($image as $frame)
$frame->cropImage($width, $height, 0, 0);

but nothing seems to work. Confusing, but

$content=file_get_contents("pic.gif");
$image=new Imagick();
$image->readImageBlob($content);
echo $image->getImageBlob();

doesn't work, too. All experiments show only the first frame of the gif.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PHP API and displaying animated gif's doesn't work?

Post by anthony »

You should be able to specify the output image format for the blob somehow!

$image=new Imagick();
$image->readImage("pic.gif");
header('Content...');
$image->writeimage("gif:-");

I think you should search and/or post in the PHP IM forum.
This is not my normal API of choice, and I don't use it regually.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply