tags:

views:

117

answers:

1

Hello,

What is the maximum width and height that ImageCopyResampled can handle? My code works for smaller images in terms of width and height. For larger images, it will disregard the coordinates, meaning the cropping starts from the upper left corner of the image.

Is there a workaround? Here's a portion:

$trgt_width = 500;
            $trgt_height = 400;
            if(copy($src_file, $trgt_file)):
                $src_image = imageCreateFromJpeg($src_file);
                $trgt_image = imageCreateTrueColor($trgt_width, $trgt_height);
                imageCopyResampled($trgt_image, $src_image, 0, 0, $x, $y, $trgt_width, $trgt_height, $width ,$height);
                imageJpeg($trgt_image, $thumb_file, 75);
            endif;

Thanks.

A: 

It depends on the maximum amount of RAM your scripts may occupy. This is usually set on your server by the administrator. The setting is called memory_limit

You can find it out using phpinfo() and searching for "memory_limit".

A rough calculation on the size needed to resize an image:

number of bytes width x number of bytes height x 3

3 for each channel of a true color image: Red, Green and blue.

So, an image 1000 x 1000 Pixels in size will take up at least 3 MB of memory. Probably more during the resize process, because the function will have to keep both the large and the resized version in memory at the same time.

In your case though, I would suspect that the image does not get cropped at all, probably because the copy operation fails because $src_file does not exist at all.

Pekka
Thanks for the answer but the problem is with the CSS. Basically what Im doing is to upload an image file via ajax then immediately loading it into the same page, displayed with a "max-width" of 700px. There Im using the plugin "Jcrop" to handle the cropping dimensions and sending such using post method. At first, the code will work for images whose width does not exceed 700px. Since this won't work for widths exceeding 700px, I just removed the max-width property and now it works. I know this is quite absurd in a programming point of view and better explanations lies beneath.
mist
Then the problem is not primarily the PHP script, but the data the crop plugin sends you. What does a test output of all the cropper parameters that get passed to your script give you? (probably `print_r($_GET);`)
Pekka