We use Imagemagick for two distinct functions.
One is to calculate the average main colors in an image's palette.
Code: Select all
$average = new Imagick( $file );
$average->quantizeImage( $numColors, Imagick::COLORSPACE_RGB, 0, false, false ); //Reduce the amount of colors to 10
$average->uniqueImageColors(); //Only save one pixel of each color
//Clone the average and modulate to brighter & darker
$bright = $average->clone();
$bright->modulateImage ( 125, 200, 100 );
$dark = $average->clone();
$dark->modulateImage ( 80, 100, 100 );
// Helper function to create the mini-images
$colors['avg'] = self::getGeneralColors($average);
$colors['dark'] = self::getGeneralColors($bright);
$colors['light'] = self::getGeneralColors($dark);
So far we've had 38,000 pieces of art submitted with little to no problems but today we had our entire server grind to a halt when someone uploaded a really high resolution JPEG (9438x12012 pixels). Short term load averages on the server went above the 50.0 mark. The server has a single Quad Core.
The thumbnails get created through a function registered to run on shutdown so that the client isn't waiting on it.
The colors get calculated through an AJAX call when a client visits the view page of the submission if and only if the colors haven't already been calculated.
So my question is fairly open ended.
How can I mitigate the load of handling both the thumbnailing and the color paletization of such large images?
If possible I'd like to fork all of this to a separate process and then lower the process priority. Is this doable (and is it a solution)?