views:

42

answers:

3

I'm using a simple image manager class, and the following code:

<?php
include('SimpleImage.php');
$image = new SimpleImage();
$image->load($target_path);
if($image->getWidth() > 500) {
    $image->resizeToWidth(500);
    echo "<p>Image Resized</p>";
} else echo "<p>Image did not need to be resized.</p>";
$image->save($target_path);
echo "<p>Image Saved</p>";
?>

The image is successfully resized when I upload an image with a width of 700, but when I upload a really big picture (width ~= 2300), it doesn't work, and I don't see any of my echo messages.

Do certain php image functions have a size limit that might be causing this?

+4  A: 

You are most likely hitting the memory_limit setting specified in php.ini.

Add error_reporting(E_ALL); to your script and see what the output is.

Use phpinfo() to find out the current memory limit setting.

It can sometimes be changed using ini_set("memory_limit", xyz). Otherwise, you need to change php.ini.

A 2300 x 2300 Pixel image is going to take up at least

2300 x 2300 x 3 = 15,870,000

= roughly 16 Megabytes of RAM (or 2300 x 2300 x 4 if there's an alpha channel) so I'd say you would need at least 24 Megabytes of RAM per script to make this work well. Maybe even more.

Pekka
+1  A: 

There is an upload file size limit ; you can to set it in your php.ini :

upload_max_filesize
post_max_size
Guillaume Lebourgeois
There is no file size limit. There is an upload size limit, but not one for dealing with file (I routinely deal with 1gb+ files)...
ircmaxell
Dear ircmaxell, as you can see if you read the question with attention "The image is successfully resized when I upload an image with a width of 700" means there is an uploading process. The problem could then from the upload part of this issue.
Guillaume Lebourgeois
Sure it could, but he asked about size limits for the img* functions. And I read your response (the original one) to answer that question (rather than trying to fix the problem)... Edit your answer to say upload file size limit, and I'd be happy to remove the downvote.
ircmaxell
All right, I fixed my semantic issue ;)
Guillaume Lebourgeois
It was more that SO locked the vote in, so I needed an edit to be able to revert it... Sorry...
ircmaxell
it's ok, no worry.
Guillaume Lebourgeois
+1  A: 

Check your error log. The chances are that you're exceeding the memory limit (memory_limit in the ini settings). Try adding ini_set('memory_limit', '32M'); to the top of the file.

And to directly answer your question, no there is no size limit on the internal functions...

ircmaxell
Didn't "M" style values work in php.ini only? I can be wrong, though, I can't quite remember right now.
Pekka
They also work in `ini_set`... At least on the versions I've used (5.2 on both win32 and linux, 5.3 on both win32 and linux)...
ircmaxell
@ircmaxell ah ok, then I misremembered. Then it's `.htaccess` files that can't parse a `php_admin_value memory_limit 32M` but need a full "32000000"
Pekka
That would make sense. I don't use Apache, so I'm not familiar with setting ini values inside of it...
ircmaxell