Prevent imagecreatefromjpeg from stopping script

I use imagecreatefromjpeg on a shared host, so if the image is large, then imagecreatefromjpeg will give me a "memory error" and exit the script.

Anyway, to avoid memmory error and just let imagecreatefromjpeg crash (Return false) instead of ending script?

+3
source share
5 answers

Try to determine the image size first: http://uk3.php.net/function.getimagesize I believe that imagecreatefromjpeg will fall if the image is larger than 3000 pixels in any size.

+3
source

imagecreatefromjpeg script, , , . : = * 3

. 1000 x 2000,

memory required= ((1000 * 2000) * 3)=600000 bytes =5.72205MB

5242880 (5 ), imagecreatefromjpeg()

if($memory_required < 5242880)
{
    imagecreatefromjpeg();
    // continue with your image related operations
}
else
{
  //handle error message, perhaps show such message as "provide image is too big"
}

PHP PHP (, )

+2

. :

GD? ()

- -

0

@ - ?

:

$x=@imagecreatefromjpeg .......

see also how to suppress errors in php: http://us3.php.net/manual/en/language.operators.errorcontrol.php

0
source

Just attach your function to the if statements, indicating that it is redirected when the function fails.

i.e. if (! imagecreatefromjpeg) {// redirects commands here};

0
source

Source: https://habr.com/ru/post/1717071/


All Articles