B
B
BloodVIRUS2020-02-15 14:10:09
PHP
BloodVIRUS, 2020-02-15 14:10:09

How to create thumbnails for gif?

Hello! I'm struggling with the problem, and I can not understand on which side it is. Server settings or php
We have a wonderful imagick that can work wonderfully with images. But things hit a dead end when I try to feed it with "gif" format.
Light files (up to megabytes) it converts easily. As soon as he feeds a heavier file (for example, a 10mb file), then that's it, nginx says 502 Bad Gateway
The file is created, but not complete (some of the frames were not created)

If I give a 7mb file, then the preview is created without problems.
But if I try to create another preview in the same php file below, the second one already breaks at 2 seconds and the web server returns 502

The server is powerful, 32 cores, 64gb DDR4
On a weak server, everything is the same, only with files in 1-2mb
Bundle of nginx 1.17 + php 7.3

code that I create a preview of:

$imagick = new Imagick("10.gif");

$format = $imagick->getImageFormat();
if ($format == 'GIF') {
  $imagick = $imagick->coalesceImages();
  do {
     $imagick->resizeImage(120, 120, Imagick::FILTER_BOX, 1);
  } while ($imagick->nextImage());
  $imagick = $imagick->deconstructImages();
  $imagick->writeImages('new_120x120.gif', true);

  $imagick = $imagick->coalesceImages();
  do {
     $imagick->resizeImage(120, 120, Imagick::FILTER_BOX, 1);
  } while ($imagick->nextImage());
  $imagick = $imagick->deconstructImages();
  $imagick->writeImages('new_121x121.gif', true);

}

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2020-02-15
@SilenceOfWinter

if it is not possible to increase the script running time, make a task for the scheduler - in cli the script is not limited in time or if possible, start the generation via js/ajax (1 file each)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question