views:

562

answers:

6

I almost always have a PHP resize script (using GD) in websites for my clients. No matter how many times I tell them to resize their huge 7MP images from their digital camera before uploading them, they still never do it. The result is an "Out Of Memory" error from the server, and the image doesn't get resized, because the original image was too large resolution-wise.

Is there a better way to resize really large images? Is there a service that offers an API that I could tap into through my script to resize these large images?

+3  A: 

You can call Imagemagick to resize the picture from your php page, but there's a security matter then if you allow system calls

Any API will use a lot of Memory, you can change your php memory_limit aswell.

Lliane
+1  A: 

You could shell out to an external programme, for example using convert.

Greg
+1  A: 

how about uploading them then queuing the resize job, a command line php script can then pick up and process (faster and can have a separate memory limit and execution time)

Question Mark
A: 
http://code.google.com/intl/en/appengine/docs/python/images/functions.html
Alix Axel
+1  A: 

If you have available ImageMagick api in your PHP configuration - use it! ImageMagick doesn't get counted in PHPs memory_limit and therefore can work with bigger files.

If you realy have no control over the server, the quick and very bad workaround is - after getting the image file from $_POST, first check the dimensions with:

<?php
$image_size = getimagesize("yourfile.jpg")
$mem_usage = $image_size[0] * $image_size[1] * 4 //4 bytes per pixel (RGBA)
if ($mem_usage > $mem_aviable) {
    die ('Please upload smaller pic. I tell you that all the time.  '.
         'Resize yout huge 7MP images from your digital camera '.
         'before uploading them.'); //Better put something more polite here.
}
enkrs
+1  A: 

Just make them resize it smaller before they upload it. MAX_FILE_SIZE