0

I have some code that adds some headers to an image:

Contents of file

<?php
$im = imagecreatefromjpeg($filepath);//full path
imagejpeg($im);
imagedestroy($im);
?>

This imagecreatefromjpeg function is giving internal server error when image is big. otherwise working

so i tried to increase memory limit

ini_set('memory_limit', '1024M'); // or you could use 1G

but same problem. Any solution? Thanks

UPDATE:

Error is

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 51024 bytes)

Image Dimensions:

Width: 12756 px

Height: 22677 px

Size: 11.6 MB

Bhumi Shah
  • 8,514
  • 5
  • 54
  • 88
  • 1
    What is the error? (exactly?) out of memory error for definite? Server error is very general, try getting more info out of PHP by turning on more error reporting. – Squiggs. Dec 19 '16 at 07:42
  • Can you provide us the error message? – Ronald Dec 19 '16 at 07:44
  • I have used error_reporting(E_ERROR); to display fatal error but page is blank and also tried to increase mem ini_set('memory_limit', '1024M'); but same blank with 500 internal server error – Bhumi Shah Dec 19 '16 at 07:53
  • How big is your image? GD uses 4 bytes per pixel of the image—so if you are processing a large image, say from a modern day 24 megapixel camera, that means ~91mb of memory. – Terry Dec 19 '16 at 08:06
  • Look: http://stackoverflow.com/questions/561066/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-codeigniter-xml – Troyer Dec 19 '16 at 08:15
  • @Terry: dimensions updated above. – Bhumi Shah Dec 19 '16 at 08:43
  • @Troyer: already checked and applied even -1 but same not working. – Bhumi Shah Dec 19 '16 at 08:43
  • 512MB is not enough for your big picture, as what @Terry said you need at least 1104MB. The error message states that you have a maximum of 512MB. So either your `ini_set` doesn't work, or you didn't post the updated number (after you changed the memory limit). Anyway; make it bigger then, let's say, 1200M and you should be fine. For _this_ particular image that is. Dunno what else you've got in the pipeline – giorgio Dec 19 '16 at 08:49
  • but if i set ini_set('memory_limit', '-1'); it is not displaying 500 internal server error that means it is working but imagecreatefromjpeg output is blank – Bhumi Shah Dec 19 '16 at 08:54
  • Does the server/machine PHP is running on has sufficient memory for that? I can see from your error message that PHP has access to 512mb of memory, despite you setting it to 1024mb. [There are several places where the memory limit is set](http://stackoverflow.com/a/4096645/395910)—make sure you've covered them. – Terry Dec 19 '16 at 08:59
  • @giorgio: i have set 2048M too but same :( – Bhumi Shah Dec 19 '16 at 10:08

0 Answers0