optimize image upload and resize/crop process

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
mechamecha
Forum Commoner
Posts: 32
Joined: Thu May 31, 2007 8:49 pm

optimize image upload and resize/crop process

Post by mechamecha »

Hello,
I'm looking for ways to optimize my current image upload and resize/crop process. I have a website w/ a registration process that includes uploading a photo.

My current implementation is as follows:
1. User uploads a photo to my web server
2. Photo is rescaled and cropped on my web server using imagick extension
3. Photo is then uploaded to s3 for storage.

The problem is that the user has to wait for all 3 steps to complete before moving on to the second phase of the registration process.

Is it possible to push any of these steps into the background so that while the photo is either getting rescaled or uploaded to s3, the user can proceed w/ registration?

Thanks!
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Re: optimize image upload and resize/crop process

Post by Inkyskin »

I had a similar issue - I used ajax to upload/resize while the rest of the form was filled in. Once the upload was complete, I enable the complete registration button. It also allows you do add a loading gif etc to show the upload is in progress, and when complete, it shows a thumbnail of the image within the form. (It's a nice effect if they are still filling i the form after the upload completes).
mechamecha
Forum Commoner
Posts: 32
Joined: Thu May 31, 2007 8:49 pm

Re: optimize image upload and resize/crop process

Post by mechamecha »

I've written my uploader in flash so that I've got a nice progress bar. And that does help a lot. However, I can't measure the progress of how long it would take to resize/crop the photo and push to s3. During that stage, I have an animation that loops and says "processing photo...please wait".

The real problem is I'm trying to get as many sign ups as possible, and what I'm finding out is ppl don't have the patience to wait for an upload if it takes too long. That's why I'm trying to make it as quick as possible.
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Re: optimize image upload and resize/crop process

Post by dbevfat »

You can put the uploaded image in a queue (you can use a database for this) which you process with a scheduler (say, cron). This way, the user can go on with registration immediately after uploading and his photo will be resized and uploaded before he completes the registration, if you set the scheduler to run often enough. There are a few problems with this, though:
- upload validation (what if the image file is in a wrong format, too large, ... , you can't notify the user immediately),
- queue size (you store the full-size images in the queue); only a problem if you expect a lot of simultaneous registrations.

But I don't think these are too serious.

regards
mechamecha
Forum Commoner
Posts: 32
Joined: Thu May 31, 2007 8:49 pm

Re: optimize image upload and resize/crop process

Post by mechamecha »

dbevfat,
Great idea! I don't think storing the full size images on my webserver would be too much of a problem since its only temporarily. Maybe I can do something where I present the user w/ the photo that's stored on my server until the cron job runs and completes the rescale/crop job. THen I swap photos and delete the original src.
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Re: optimize image upload and resize/crop process

Post by dbevfat »

That would work, but displaying the original image back to the user can be problematic if the images are large. And they'll probably be large, if I know anything about users. :)
Post Reply