views:

36

answers:

2

I have narrowed down my problem to show the size of the file matters. I don't know when the file is to big however. How can I catch the error. A 1.1mg file causes imagecreatetruecolor to bail but it chuggs along just fine when processing a 688k file.

Thanks

+1  A: 

The function will throw an error if you try to create an image too big. Just suppress the error and handle it yourself. For example,

$img = @imagecreatetruecolor(100000, 100000);
if ($img === false)
{
    // Handle error
}
Stephen Melrose
Thanks Stephen but since I was having a memory problem this would not catch the error.
Brick
A: 

From what I can tell in the PHP/GD documentation, this function creates a 24-bit RGB image with black as the default color. The width and height it takes as arguments are ints for the pixel dimensions. Therefore to calculate size, you could multiply them as follows to determine if the raw image (before compression) is to blame:

1536 * 1962 = 3,013,632 pixels
3,013,632 * 24 = 72,327,168 bits
72,327,168 / 8 = 9,040,896 bytes

1024 * 768 = 786,432 pixels
786,432 * 24 = 18,874,368 bits
18,874,368 / 8 = 2,359,296 bytes

It seems unusual to me that this function would cause problems at a size of 1.1 MB but perhaps you are referring to a compressed image such as a jpg, where the actual raw size could be much, much greater. (As you can see a "small" image of 1024x768 is still well over 1.1 MB raw.)

JYelton
This gave me the tip I needed. I just bumped up the php memory limit to 64mgs and the process completed. Thanks to both of you
Brick