当文件大小超过2mb时,Imagick无法调整GIF图像的大小

时间:2018-01-11 18:40:09

标签: php imagemagick gif image-resizing imagick

我正在使用Imagick PHP扩展程序将GIF图像调整为多种尺寸。当我尝试使用3mb大小的GIF图像时,它不会调整大小。但对于小于1mb的图像,它们会成功调整大小。

如果有其他人遇到此问题,请提出建议!

这是我的代码

if ($extension === 'gif') {
    $imagick =  new Imagick($_FILES['file']['tmp_name']);

    foreach ($imageFolders as $imageFolder => $size) {

        if ($imagick->getImageWidth() > $size['minWidth']) {
            $width = $size['maxWidth'];
            $height = $size['maxWidth'];
        } else {
            $width = $imagick->getImageWidth();
            $height = $imagick->getImageHeight();

        }

        $imagick->coalesceImages();

        do {
            $imagick->scaleImage($width, $height, Imagick::FILTER_BOX, 1);
        } while ($imagick->nextImage());

        $imagick = $imagick->deconstructImages();
        $imagick->writeImages($imagePath, true);

    }

    $imagick->clear();
    $imagick->destroy();

}

结果:转换列表资源

File         Area       Memory          Map         Disk    Thread         Time
-------------------------------------------------------------------------------
 768      7.951GB    3.7025GiB    7.4049GiB    unlimited         2    unlimited

1 个答案:

答案 0 :(得分:0)

$imagick =  new Imagick($_FILES['file']['tmp_name']);

foreach ($imageFolders as $imageFolder => $size) {

    if ($imagick->getImageWidth() > $size['minWidth']) {
        $width = $size['maxWidth'];
        $height = $size['maxWidth'];
    } else {
        $width = $imagick->getImageWidth();
        $height = $imagick->getImageHeight(
    }

    $imagick = $imagick->coalesceImages();

    foreach($imagick as $frame){
        $frame->thumbnailImage($width , $height ); 
        $frame->setImagePage($width , $height , 0, 0); 
    }

    $imagick = $imagick->deconstructImages();
    $imagick->writeImages($imagePath, true);

}

$imagick->clear();
$imagick->destroy();