0

I am using phpimageworkshop to resize images but i am experiencing the following problem. Depending on my jpg file, the library works or doesn't work. To test it, i have the following code:

use PHPImageWorkshop\ImageWorkshop; /*http://phpimageworkshop.com/*/
require_once('lib/PHPImageWorkshop/ImageWorkshop.php'); 

$layer1 = ImageWorkshop::initFromPath('uploads/img1.jpg');
echo $layer1->getWidth();

$layer2 = ImageWorkshop::initFromPath('uploads/img2.jpg');
echo $layer2->getWidth();

it works fine with file img1.jpg, but it do not work with img2.jpg, the echo returns nothing. You can test with the following files: http://francois-deneuville.fr/stackoverflow/ do you know why?

  • 1
    Perhaps the image is too large. Does the library not have some form of error handling? – Pekka Dec 28 '13 at 17:53
  • Do you have [error reporting turned on](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php)? The second image is much larger than the first; it wouldn't surprise me if you were hitting a PHP memory limit. Check your server error logs. Your second image is 4,288x2,848 pixels; at a conservative 16 bits per pixel, it'll need about 24MB of memory to hold it when it's loaded. – Matt Gibson Dec 28 '13 at 17:54
  • no i don't have error reporting turned on. I'll check that out – ApneaDeepBlue Dec 28 '13 at 17:58
  • Also, temporarily put in a call to [phpinfo()](http://php.net/phpinfo), and see what it says your memory_limit is, for starters. But, basically, turn on error reporting, because the chances are you're running into an error that you're not seeing. And you'll need more memory to do the resizing, too; you'll need to have the original and the resized image in memory at once, at least briefly. – Matt Gibson Dec 28 '13 at 17:59
  • I have run phpinfo, and my memory limit is 32M. I will turn on error reporting to know more. – ApneaDeepBlue Dec 28 '13 at 18:04
  • You were all right, it was definitely a problem of memory (not image bytes size but too high pixel size) . I have modify the php.ini file to read the error, and set 'memory_limit = 128M'. It works fine now. Thanks to all you – ApneaDeepBlue Dec 29 '13 at 00:17

2 Answers2

0

Your second image is far larger than the first.

Verify that your server can handle max uploads of 2mb. To do so, call out within your script:

<?=phpinfo();?>

Scroll down to *upload_max_filesize* and verify that your max file size that is accepted is greater than or equal to 2mb.

To adjust your upload file size, go to your php.ini file -on UNIX, this can be found on your /etc/php5/apache2.

Scroll down and find:

; Maximum allowed size for uploaded files.
;http://php.net/upload-max-filesize       
upload_max_filesize = 2M   

This should fix your problem if it is indeed a max file size issue.

justinpage
  • 623
  • 7
  • 18
  • Do an experiment, set your max file size to 2mb. Having it at 32mb is not a proper max file size for upload -especially images. Check to see if your file upload will work then. – justinpage Dec 28 '13 at 18:13
  • To fix the problem, i have changed the value of memory_limit up to 'memory_limit = 128M'. It works. – ApneaDeepBlue Dec 29 '13 at 00:19
0

To fix the problem, i have changed the value of memory_limit up to 'memory_limit = 128M'. This value had be adjusted in the php.ini file.

Make sur you have modified the good php.ini file by lunching <? phpinfo();?> and scroll down to 'memory_limit'