S
S
Sergey Beloventsev2016-07-26 14:44:29
Yii
Sergey Beloventsev, 2016-07-26 14:44:29

Why does the Imagine error occur?

I'm trying to organize the cropping of files (but it turned out that initially) no one cropped them, so I had to take information about finding photos from the database, here's the code itself

$image=Image::find()->all();
     $imgcrop=$imagine->imagerisize($image); 


    public function imagerisize($models){
            foreach($models as $model) {
                $path = Yii::getAlias('@frontend/web/image/') . $model->path;
                $img = Image::getImagine()->open($path . '/' . $model->name);
                $size = $img->getSize();
                $ratio = $size->getWidth() / $size->getHeight();
                $widthcar = 200;
                $heightcar = round($widthcar / $ratio);
                Image::thumbnail($path . '/' . $model->name, $widthcar, $heightcar)->save($path . 'carusel-' . $model->name, ['quality' => 90]);
                $widthind = 240;
                $heightind = round($widthind / $ratio);
                Image::thumbnail($path . '/' . $model->name, $widthind, $heightind)->save($path . 'index-' . $model->name, ['quality' => 90]);
                $widthcat = 220;
                $heightcat = round($widthcat / $ratio);
                Image::thumbnail($path . '/' . $model->name, $widthcat, $heightcat)->save($path . 'category-' . $model->name, ['quality' => 90]);
                $widthtop = 92;
                $heighttop = round($widthtop / $ratio);
                Image::thumbnail($path . '/' . $model->name, $widthtop, $heighttop)->save($path . 'top-' . $model->name, ['quality' => 90]);
                $widthnews = 42;
                $heightnews = round($widthnews / $ratio);
                Image::thumbnail($path . '/' . $model->name, $widthnews, $heightnews)->save($path . 'news-' . $model->name, ['quality' => 90]);
            unset($model);
            }
        return true;
        }

it gives this error
Imagine\Exception\RuntimeException
        Save operation failed
        Caused by: ImagickException
        Insufficient memory (case 4)

The question is how to fix this error.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Stepanov, 2016-07-28
@Vdm17

Looking for a translation from English? Imagick complains about running out of memory. Options for action:

  • add memory script (not the best)
  • after creating each thumbnail, force the memory for the Imagine object to be cleared

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question