Michael
Michael

Reputation: 2598

Batch resizing 50+ large images in ColdFusion

I'm trying to upgrade a photo gallery system we have to be able to take a folder of 50-100 large (~500K-1MB) images and batch process a thumbnail, medium, and high-resolution version for each (and add a record for each to a database).

I wrote a <cffunction> that does exactly that. It works well with a small folder of smaller images, however a larger folder of large images will generate serious performance issues and throw random errors (timeouts or file permission issues) after only completing about 10 of the 50 or more I throw at it.

My question: how do I accomplish something this intensive while minimizing the performance affect on the entire server? Is it even possible with ColdFusion alone, or do I need to look into other server plugins? (I don't have any experience in this area.)

Update: With my shared hosting limitations, I'm currently redirecting my attention to client-side resizing (Flash) before uploading so the server only has to upload/move and create the db records. However, I would need something that resizes the original images into a thumb/medium/large version for each and uploads them all. Right now I'm only seeing examples that upload one resized image, but I'll try playing around with the sources.

Update 2: I've seen some pretty cool demos that showcase resizing images using the HTML5 <canvas> and I'm going to try my hand at that. I'll post back any results.

Upvotes: 1

Views: 623

Answers (4)

James Buckingham
James Buckingham

Reputation: 815

Is the issue maybe more that you're trying to do this all in one process?

A couple of suggestions would be:-

Use cfthread which would allow you to run the same process in parallel, each of which could handle a small amount of your imagery at one time. Saying that you're on a shared host though I'm not sure if that's going to be available to you. You'd have to check with the provider.

Another option could be to setup a scheduled task that runs every minute or so. That takes in XX amount of imagery, does the work and then stops. The next schedule would pick up the next batch and so on...

That would be less process intensive but I'm not sure how you would manage user interaction if they're expecting some kind of result back. You'd also need to take into account with timings i.e. what if the previous scheduled task hadn't finished.

James

Upvotes: 1

Henry
Henry

Reputation: 32905

<cfexecute> with ImageMagik would beat resizing with <cfimage> in terms of speed and efficiency.

http://www.imagemagick.org/www/mogrify.html

Upvotes: 3

Adrian J. Moreno
Adrian J. Moreno

Reputation: 14859

Well, maybe a combination of Async Gateways, JVM tuning, possibly adding more RAM or splitting image processing onto a separate physical server that does not run the main application.

Upvotes: 1

Related Questions