Reducing server load convert + montage multiple images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
SEO

Reducing server load convert + montage multiple images

Post by SEO »

Dear ImageMagick Experts,

I was wondering if someone on this forum could advise me what the best setup would be to convert (resize) multiple (5 tot 10) images and after that merging them using montage.

I run a website that offers news for 10.000 cities and 1,5 times per day it will create a merged image with 5 of the latest news images to display in a slider on the homepage.

During this update PHP code will run the following:

Code: Select all

$target_location = 'some_location.jpg';
$imgs = array();
$temp_directory = 'xxxx/';
foreach($newsitem as $item) {
	$imagelocation = $item['image'];
	$imagedata = file_get_contents($imagelocation);
	$temp_file = $temp_directory . $item['id'].'.jpg';
	file_put_contents($tmp_file,$imgdata);
	exec("convert ".$tmp_file." -resize 350x210^ -gravity center -extent 350x210 -quality 95 ".$tmp_file."",$array);
	$imgs[] = $temp_file;
}
// Then montage it together
$imgs_line = '';
foreach ($imgs as $img) {
	if ($imgs_line) {
		$imgs_line .= ' ';
	}
	$imgs_line .= $img;
}
exec("montage ".$imgs_line." -tile x1 -geometry +0+0 -quality 85 ".$target_location."",$array);
Normally the load of the server is stable about 0,02 to 0,5, but sometimes it shoots up to over 200 and I notice in TOP a lot of convert and montage commands, so I am expecting this ImageMagick code is the cause or otherwise perhaps the (possible) ImageMagick OpenMB bug.

I am wondering if I may be doing something wrong/ineffective. I already investigated Mogrify, but it seems running a command at a time is more effective because mogrify loads all images into memory and then processes it one by one which causes a higher memory load according to the documentation.

I hope someone would be able to help me/provide advise on what the best (most efficient) method is to process multiple images and could provide a clue on why my server load is jumping so high.

Best Regards,
Jan Jaap

p.s. my ImageMagick version is:

Code: Select all

Version: ImageMagick 6.5.4-8 2009-08-04 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
Post Reply