imagick PHP failes resizing gif images larger than 2mb

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
DiFdo
Posts: 3
Joined: 2018-01-16T10:50:04-07:00
Authentication code: 1152

imagick PHP failes resizing gif images larger than 2mb

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