I use PHP 7.1 with GD library.
My script downloads images and resizes it before saving. Server has 256MB of memory (can't increase).
Some of images have large physical size (not file size), greater than 50Mpx. When I try to resize it with GD, memory limit error raises in this line:
<?php
$image = imagecreatefromjpeg($file);
Script gets images in form of PSR-7 HTTP-response. Before resizing image I need to test it if it's enough memory to resize image?
I've tried to test images by file size, but it discards images with ok physical size, but large file size:
<?php
$fileIsOk = (int)$response->getBody()->getSize() <= SOME_MAGIC_SIZE_IN_BYTES;
if ($fileIsOk) {
// do the stuff
}
For example, my script fails with image 50.2Mpx 1.51MB, but ok with 3.6Mpx 1.02MB.
My idea is to test image by getting Mpx count:
So I need to test if script can resize image in conditions of limited memory based on Mpx count. How can I get it from PSR-7 response object?