Off-load image thumbnail creation

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
marios88's picture

Hi all,

Even cheap modern digital cameras can take pictures up to 12MP. So there comes the problem:

A user will upload many large images that will have to be cropped and scaled down twice or more times to create thumbnails, resulting in high server load and memory usage.

Is there any way available or suggestions to offload image thumbnail creation to another machine in order to save critical resources?

Comments

Yep!

imageinfo_cache

--
Linux: Web Developer
Peter Bowey Computer Solutions
Australia: GMT+9:30
(¯`·..·[ Peter ]·..·´¯)

+1

rjbrown99's picture

If you like any type of performance, just keep checking on what mikeytown2 is up to. Imageinfo cache works well and is getting better.

Upload Tool

mkabot68's picture

I'd integrate a Java or Flash upload tool that will create the thumbnails on the client side.

Sounds interesting but i

marios88's picture

Sounds interesting but i think this would be a security risk

There isn't anymore of a

Jamie Holly's picture

There isn't anymore of a security risk than allowing regular uploads through a standard HTML post. Validating that the upload is an actual image would be a server side requirement just the same as any other upload. Validating it with getimagesize, insuring that it meets the criteria of your thumbnail dimensions, is the way to go here.

I've never seen any actual external server software for thumbnail creation, but writing one wouldn't be all that complicated. Either go with a RESTful API or where the thumbnail server checks a queue on cron then sends the image back to Drupal. I've done something similar with video encoding servers for Drupal sites before. Going the API route you do have to put a fallback mechanism is - if the server isn't available then have Drupal go ahead and handle it. With the cron method, you need to put a system in to let the user know their image is being processed. Also I would keep the server with the same hosting company or you will have the data between the web server and thumbnail server count against your monthly bandwidth allowance.


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

There isn't anymore of a

dalin's picture

There isn't anymore of a security risk than allowing regular uploads through a standard HTML post.

Well that's not quite true. As we know from the recent attack on mysql.com, simply having the Java plugin enabled in your browser is a security risk.

Also if you are running some thirdparty Flash or Java widget, and you are not familiar with the ways that Flash or Java can be exploited, then you are putting your trust in that third party who may or may not understand the security of the platform better than you do. This is illustrated in the recent security announcement for the Cumulus module.

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

It's not anymore of a

Jamie Holly's picture

It's not anymore of a security risk than anytime you use Java or Flash.

Well that's not quite true. As we know from the recent attack on mysql.com, simply having the Java plugin enabled in your browser is a security risk.

But what was the actual mechanism of that attack? It was a JavaScript file, so the same can be said for anytime you have javascript enabled in your browser (and is true). Should we stop shipping Drupal with Javascript because of this? No. It just means we have to be extra vigilant when coding and thinking of possible ways that attackers can get us.

(That particular JS malware on MySQL can also exploit security holes in browsers, yet we need browsers or the internet will get very boring and a lot of us will become very broke!)

This is illustrated in the recent security announcement for the Cumulus module.

I think this is a perfect example. Cumulus doesn't ship with the source code for the AS file. Instead you have to know that Cumulus is actually a Wordpress project and go get the source code from wordpress.org (it wasn't even open source until version 1.12). Basically I won't install any 3rd party Java or Flash file for a client without the source code unless they sign a liability release because I have no idea what the applet is actually doing behind the scenes.


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

Jumploader

mkabot68's picture

www.jumploader.com you can purchase the source code...

PLUpload is open source and

Jamie Holly's picture

PLUpload is open source and there's even a Drupal module for it:

http://drupal.org/project/plupload


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

PLUpload

rjbrown99's picture

PLupload is great, I use it quite extensively. It just doesn't solve the problem of offloading the image generation. That particular problem is caused by the imageapi/core calling either GD or ImageMagick to create an image. Using ImageMagick as an example, that in turn fires off a command-line 'convert' process with the appropriate arguments. Converting one or a few images isn't a problem, but converting many at once can drag a server to its knees - especially if it happens on the same machine that is doing other things (like running MySQL, serving web content, etc.)

I have a rather long series of thoughts here: http://drupal.org/node/1138098

Right now, after MUCH thought, I'm back around to simply firing up a second host and using imageinfo_cache to offload image creation to the other machine. That may or may not work if it also overruns my second machine. In that case, I'm going to enhance imageinfo_cache with Queue API to offload all creation requests to a queue, then dequeue them. I already wrote much of that code directly in a fork of D6 imageapi but I like mikeytown2's imageinfo_cache approach better.

It's not a trivial problem at scale.

PLupload can handle image

Jamie Holly's picture

PLupload can handle image resizing on the client side though before the file is sent to the server. It's resize under general options:

http://www.plupload.com/documentation.php

Of course the problem here is that it will just upload that resized image and not the thumbnail + original. I don't think there's any way to get it to do both.


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

ImageCache

mikeytown2's picture

The ImageCache module makes client side resizing not easy to do. Having the original is always the best option when using modules like ImageCache

That's the big problem. Of

Jamie Holly's picture

That's the big problem. Of course if you decide you want your originals to be no more than X by Y you could always have a applet like PLUpload resize to that and upload, then let imagecache take over from there. That would alleviate some of the stress from people uploading super large images or forcing people to resize before uploading.


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

There are quite a few 3rd

mkabot68's picture

There are quite a few 3rd party tools you can plug into Drupal relatively easy.

I use www.jumploader.com which has plenty of options to meet any need.

Same security risk as uploading the image file in the first place...

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week