I have written a PHP script that allows me to rotate an image, by using PHP's imagerotate()
function. It works great with most of the photos I have tested. However, the script crashes when trying to rotate larger photos ( > 644 KB, 2112px x 2816px). This isn't a very large photo, but my script only crashes when the photo is around this size or larger. Is there a file size limit when using imagerotate()?
Asked
Active
Viewed 508 times
0

Ajay Mohite
- 119
- 3
- 13
-
3More likely a memory limitation; check `ulimit -m` output or `php.ini` configuration limit for maximum allowed memory. – sarnold Jul 18 '12 at 23:50
-
The same problem exists on my local MAMP testing environment, and my Linux production server. I have increased the max. script memory for PHP (on the production server) to 128 MB and I still have the same issue. – Ajay Mohite Jul 18 '12 at 23:56
-
How does it *crash*? what errors do you get ? – Jul 18 '12 at 23:59
-
2In that case, look in your webserver logs. – sberry Jul 19 '12 at 00:00
-
A naive storage for that image is going to require 22 megabytes. You'll probably need twice that (for input _and_ output), plus whatever overhead is required for reading and writing the compressed images, plus whatever work is undertaken for the actual rotation, in addition to the usual overhead of starting the PHP interpreter in the first place. Try 256M. Or, take a look at the memory used for the slightly smaller images that still work... – sarnold Jul 19 '12 at 00:06
-
Okay, thanks for the suggestion. I checked my error logs, and it said there is a problem with this line in my script: `$rotate = imagerotate($source, 90, 0);`. The error was "Allowed memory size of 33554432 bytes exhausted (tried to allocate 8448 bytes)". – Ajay Mohite Jul 19 '12 at 00:09
-
1dangerous but try : ini_set('memory_limit', '-1'); =all the memory you got. – Jul 19 '12 at 00:12
-
This just doesn't seem right. The photo is only 644 KB. I feel like something else must be going on. I increased the memory to 512 MB and it still doesn't rotate the image. – Ajay Mohite Jul 19 '12 at 00:31
-
your question is tagged "PHP", but doesn't contain any PHP code. Show use your code (only the relevant bits, we don't want hundreds of lines!) – Jocelyn Jul 19 '12 at 00:47
1 Answers
-1
You could try a wrapper for GD such as PHP Image Magician to simplify the process.

Jarrod
- 9,349
- 5
- 58
- 73