Page 1 of 1

imagick PHP failes resizing gif images larger than 2mb

Posted: 2018-01-16T11:08:47-07:00
by DiFdo
I'm using iMagick php extension for resizing animated gif image into several sizes. But when I upload a gif image which is size of 2mb or more. it failes the process. Either not resizing at all or else resizing few images but without having same animation frame rate. Below I posted tw code smaples which I've tried but neither of them didn't worked for me as expected. Can anyone advice me how to proceed this?

Try 01

Code: Select all

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();

}
try 02

Code: Select all

$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();