【问题标题】:Imagick only giving single page for gif resizeImagick 只为 gif 调整大小提供单页
【发布时间】:2015-04-19 19:36:54
【问题描述】:

我查看了不同的问题(例如thisthis)和php documentation。我检查了我的 Imagick 版本并且 imagick::getVerison() 函数返回

{"versionNumber":1641,"versionString":"ImageMagick 6.6.9-7 2014-03-06 Q16 http:\/\/www.imagemagick.org"}

所以我没有使用问题和文档中提到的错误版本(或者至少我不认为我是)。我正在使用以下代码尝试调整 gif 的大小。

public function resizeGif($path, $x, $y, $maintainRation = true) {
    $imageObject = new Imagick($path);

    $format = $imageObject->getImageFormat();
    if ($format != "GIF") {
        return false;
    }

    $imageObject = $imageObject->coalesceImages();

    $y = $this->getAspectRation($imageObject->getImageWidth(),
        $imageObject->getImageHeight(),
        $x);

    foreach ($imageObject as $frame) {
        $frame->thumbnailImage($x, $y);
        $frame->setImagePage($x, $y, 0, 0);
    }

    $newImageDir = 'img' . rand();
    $imageObject = $imageObject->deconstructImages(); 
    $imageObject->writeImages($newImageDir, true);

    $md5 = md5_file($newImageDir);

    return $md5;
}

但是当我运行该函数时,会创建 gif 并调整其大小,但没有动画。 this is the image I'm testing with

【问题讨论】:

    标签: php gif imagick


    【解决方案1】:

    它对我来说很好用。您可能使用的是旧版本的 Imagick,它具有 this bug

    如果是这样,您可以升级或解决它:

    file_put_contents('img' . rand().".gif", $imageObject->getImagesBlob());
    

    顺便说一句,ImageMagick 的 6.6.9-7 版将在今年 4 月推出 4 年 - 可能也值得升级。

    【讨论】:

      猜你喜欢
      • 2013-06-11
      • 2012-06-28
      • 2015-06-16
      • 2018-06-21
      • 1970-01-01
      • 2014-05-23
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      相关资源
      最近更新 更多