PHP Imagick GIF 动画不保留 [英] PHP Imagick GIF Animation Is Not Preserved
问题描述
我在上传 gif 和保留动画时遇到了一些麻烦.我的代码如下所示:
I am having a bit up trouble upload gifs and keeping their animation. My code looks like this:
$image = new Imagick($data['file']);
$object -> uploadFile('test.gif', $image -> getImageBlob());
当使用 getImageBlob() 时,gif 似乎没有保留.我已经尝试过事件:
And the gif goes not seem to be preserved when the getImageBlob() is used. Ive event tried:
$image = new Imagick($data['file']);
$image = $image->coalesceImages();
$image = $image->deconstructImages();
$object -> uploadFile('test.gif', $image -> getImageBlob());
有没有办法在使用 getImageBlob() 时保留 gif?
Is there way I can preseve the gif when using getImageBlob()?
推荐答案
尝试 <代码>Imagick::getImagesBlob 而不是 Imagick::getImageBlob
.getImagesBlob
将返回加载图像的序列,而不是单个图像;在这种情况下,GIF 中的每一帧.
Try Imagick::getImagesBlob
instead of Imagick::getImageBlob
. getImagesBlob
will return the sequence of loaded images, as opposed to just a single image; in this case, the each frame in the GIF.
快速检查 PHP 5.5.7 和 PECL imagick 3.1.2 揭示了两种不同的行为:
A quick check with PHP 5.5.7 and PECL imagick 3.1.2 reveals two different behaviors:
$image = new Imagick('test.gif');
var_dump(strlen($image->getImagesBlob())); // int(4316519)
var_dump(strlen($image->getImageBlob())); // int(61413)
这篇关于PHP Imagick GIF 动画不保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!