Very slow "writeImages"
Posted: 2017-03-24T12:34:21-07:00
Hey. I read many forums and did not find the answer.
I use:
PHP Version 5.3.3
imagick module version 3.1.2
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version ImageMagick 6.7.2-7 2016-06-16 Q16
Everything works on a virtual server on "centos" - there are access to all the settings. I need to crop the animated GIF, resize it and save it - make a thumbnail for the preview.
Solve the problem so:
The standard solution. Everything is working.
But when i open GIF size bigger 5MB with the number of frames from 20. (stalker-zona-tvorchestva.ru/temp/579.gif)
And the problem begins - the function $image->writeImages($destination_file, true); - It makes 50 seconds. Its very slow
To track the execution time, I surrounded each function with the output to the log.
Fragment of the log below:
On online services processing of the specified GIF occurs in 1-2 seconds, I have without saving 1-2 seconds.
I ask help how to fix the problem and find its solution !!
I use:
PHP Version 5.3.3
imagick module version 3.1.2
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version ImageMagick 6.7.2-7 2016-06-16 Q16
Everything works on a virtual server on "centos" - there are access to all the settings. I need to crop the animated GIF, resize it and save it - make a thumbnail for the preview.
Solve the problem so:
Code: Select all
$image = new Imagick($original_file);
$image = $image->coalesceImages(); // We do coalesceimages again because now we need to resize
foreach ($image as $frame) {
$i++;
$frame->cropImage($width, $height, $x, $y); // You crop the big image first
$frame->resizeImage($square_size, $square_size,Imagick::FILTER_LANCZOS,1);
$frame->setImagePage(0, 0, 0, 0); // Remove canvas
}
$image = $image->deconstructImages();
$image->setImageCompressionQuality(60);
$image->stripImage();
$image->writeImages($destination_file, true);
$image->clear();
$image->destroy();
But when i open GIF size bigger 5MB with the number of frames from 20. (stalker-zona-tvorchestva.ru/temp/579.gif)
And the problem begins - the function $image->writeImages($destination_file, true); - It makes 50 seconds. Its very slow
To track the execution time, I surrounded each function with the output to the log.
Fragment of the log below:
I can not understand why the image saved in the file so slowly. Nowhere is such a problem.21:34:07.0.3866069316864 frame 21
21:34:07.0.38687705993652 cropImage start
21:34:07.0.38782596588135 cropImage end
21:34:07.0.3881208896637 resizeImage start
21:34:07.0.39612603187561 resizeImage end
21:34:07.0.39630103111267 setImagePage start
21:34:07.0.39666104316711 setImagePage end
21:34:07.0.3970320224762 frame 22
21:34:07.0.39730310440063 cropImage start
21:34:07.0.39823389053345 cropImage end
21:34:07.0.39853692054749 resizeImage start
21:34:07.0.40652990341187 resizeImage end
21:34:07.0.40671300888062 setImagePage start
21:34:07.0.40713906288147 setImagePage end
21:34:07.0.40750408172607 frame 23
21:34:07.0.40775609016418 cropImage start
21:34:07.0.4087290763855 cropImage end
21:34:07.0.40902996063232 resizeImage start
21:34:07.0.41764903068542 resizeImage end
21:34:07.0.41790294647217 setImagePage start
21:34:07.0.41828489303589 setImagePage end
21:34:07.0.41867995262146 deconstructImages start
21:34:07.0.43926596641541 deconstructImages end
21:34:07.0.43949699401855 setImageCompressionQuality start
21:34:07.0.43990802764893 setImageCompressionQuality end
21:34:07.0.44032788276672 writeImages start
21:34:57.0.19726300239563 writeImages end
On online services processing of the specified GIF occurs in 1-2 seconds, I have without saving 1-2 seconds.
I ask help how to fix the problem and find its solution !!