I'm running imagemagick via PHP. Here are some snippets of the code.
//#####################################
// resize image
//#####################################
// resize if width exceeds maximum allowed
if ($width > $attachmentMaxWidth)
{
$imagick = new Imagick();
$imagick->readImage($tempFullPath);
$imagick->resizeImage($attachmentMaxWidth, 0, Imagick::FILTER_LANCZOS, 1);
$imagick->writeImage($tempFullPath);
$imagick->clear();
$imagick->destroy();
// get new image size
list($width, $height) = getimagesize($tempFullPath);
}
// resize if height exceeds maximum allowed
if ($height > $attachmentMaxHeight)
{
$imagick = new Imagick();
$imagick->readImage($tempFullPath);
$imagick->resizeImage(0, $attachmentMaxHeight, Imagick::FILTER_LANCZOS, 1);
$imagick->writeImage($tempFullPath);
$imagick->clear();
$imagick->destroy();
// get new image size
list($width, $height) = getimagesize($tempFullPath);
}
//#####################################
// create thumbnail
//#####################################
// declare variable
$thumbSaved = '';
// define thumbpath
$thumbpath = $externalDataPath . '/attachments/' . $lastfolder . '/' . $dataId . '-' . $filehash . '.jpg';
// create blank file
if (!file_exists($thumbpath))
{
touch($thumbpath);
chmod($thumbpath, octdec($filePermission));
}
// save thumbnail if smaller than maximum width and height
if ($width <= $attachmentThumbnailDimensions AND $height <= $attachmentThumbnailDimensions)
{
// copy attachment
copy("$attachmentFullPath", "$thumbpath");
// thumbSaved
$thumbSaved = 'yes';
}
// if thumbnail not saved
if ($thumbSaved == '')
{
// define imagick
$imagick = new Imagick();
$imagick->readImage($attachmentFullPath);
// if image has a transparency
if ($imagick->getImageAlphaChannel())
{
// define thumbpathTemp
$thumbpathTemp = $temporaryImageDirectory . $filehash;
// create image
$image = new Imagick($attachmentFullPath);
// resize image
if ($width == $height)
{
$image->thumbnailImage($attachmentThumbnailDimensions, $attachmentThumbnailDimensions);
}
if ($width > $height)
{
$image->thumbnailImage($attachmentThumbnailDimensions, 0);
}
if ($width < $height)
{
$image->thumbnailImage(0, $attachmentThumbnailDimensions);
}
// save image
$image->writeImage($thumbpathTemp);
$image->clear();
$image->destroy();
// update attachment file
rename("$thumbpathTemp", "$thumbpath");
// thumbSaved
$thumbSaved = 'yes';
}
// if image is animated
if ($numberImages > 1)
{
// define thumbpathTemp
$thumbpathTemp = $temporaryImageDirectory . $filehash;
// create image
$image = new Imagick($attachmentFullPath);
// coalesce images
$image = $image->coalesceImages();
// resize image
foreach ($image as $frame)
{
if ($width == $height)
{
$frame->thumbnailImage($attachmentThumbnailDimensions, $attachmentThumbnailDimensions);
}
if ($width > $height)
{
$frame->thumbnailImage($attachmentThumbnailDimensions, 0);
}
if ($width < $height)
{
$frame->thumbnailImage(0, $attachmentThumbnailDimensions);
}
}
// deconstruct images
$image = $image->deconstructImages();
// save image
$image->writeImages($thumbpathTemp, true);
$image->clear();
$image->destroy();
// update attachment file
rename("$thumbpathTemp", "$thumbpath");
// thumbSaved
$thumbSaved = 'yes';
}
}
// if thumbnail not saved
if ($thumbSaved == '')
{
// resize image
$imagick->resizeImage($attachmentThumbnailDimensions, $attachmentThumbnailDimensions, Imagick::FILTER_QUADRATIC, .5, true);
$imagick->writeImage($thumbpath);
$imagick->clear();
$imagick->destroy();
}
A few example gif animations that cause the errors are:
https://upload.wikimedia.org/wikipedia/ ... wave3D.gif
http://animatedphysics.com/photons/anim ... on_mid.gif
http://www.spoonfedrelativity.com/web_i ... mentum.gif
https://upload.wikimedia.org/wikipedia/ ... 8-cell.gif
The exact error is:
memory allocation failed `.../public_html/tmp/ 9c1f51293667f29d3664c295cb02429f' @ error/gif.c/WriteGIFImage/1623
/tmp has 1.3G free space