M
M
Maxim Timofeev2015-11-06 19:06:09
Yii
Maxim Timofeev, 2015-11-06 19:06:09

How to reduce RAM consumption when resizing a photo?

there is a site on yii2. There is an extension. which uses GD and resizes pictures. Faced a problem. With a photo size of about 3 mb - there is not enough RAM.
Resizing goes in several stages. An original and 3 miniatures are created.
How to bypass it? There are developments? Ideas? Offers?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Stalker_RED, 2015-11-06
@webinar

In GD, RAM consumption directly depends on the number of pixels. How much the picture weighs in this case - it does not matter.
If your host has imagemagick, use it.
imagemagick has a lot of features, but the quality of the documentation is lame (or I didn't find it).
Here's a simple wrapper for you: pastebin.com/PF9j5wWF
Usage example:

$img = new SimpleImagick($original_fullpath);
$img->resizeDownTo(256, 256);
$img->save($thumb_fullpath, IMAGETYPE_JPEG, 100);

O
OnYourLips, 2015-11-06
@OnYourLips

In the PHP settings write:
memory_limit = 256M

A
Alexander Gubarev, 2015-11-08
@AlexGx

I recommend using more efficient engines instead of gd, for example, VKontakte uses Gmagick - a more efficient fork of imagick

A
alexeytru, 2017-08-13
@alexeytru

gc_collect_cycles(); periodically force the garbage collector to run, especially if the processing is batched, in a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question