The most efficient way to create thumbnails?

I have a huge amount of thumbnails. I am currently using ImageMagick, but it turned out to be too inefficient (it is too slow, it uses too much CPU / memory, etc.).

I began to evaluate GraphicsMagick, from which I expected to get “wow” results. I have not received them. Can someone take a quick look at my test script (a simple comparison of speed and file size while the CPU and memory are not tested yet):

http://pastebin.com/2gP7Eaxc

Here is an example of the output I received:

'gm convert' took 75.0039 seconds to execute 10 iteration(s). 'convert' took 83.1421 seconds to execute 10 iteration(s). Average filesize of gm convert: 144,588 bytes. Average filesize of convert: 81,194 bytes. 

GraphicsMagick is not much faster - and the size of the output files is MUCH higher than ImageMagick.

+6
php image-processing imagemagick graphics graphicsmagick
source share
3 answers

I want to use GD2, I will try to use this function. This is pretty easy to use:

 function scaleImage($source, $max_width, $max_height, $destination) { list($width, $height) = getimagesize($source); if ($width > 150 || $height > 150) { $ratioh = $max_height / $height; $ratiow = $max_width / $width; $ratio = min($ratioh, $ratiow); // New dimensions $newwidth = intval($ratio * $width); $newheight = intval($ratio * $height); $newImage = imagecreatetruecolor($newwidth, $newheight); $exts = array("gif", "jpg", "jpeg", "png"); $pathInfo = pathinfo($source); $ext = trim(strtolower($pathInfo["extension"])); $sourceImage = null; // Generate source image depending on file type switch ($ext) { case "jpg": case "jpeg": $sourceImage = imagecreatefromjpeg($source); break; case "gif": $sourceImage = imagecreatefromgif($source); break; case "png": $sourceImage = imagecreatefrompng($source); break; } imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output file depending on type switch ($ext) { case "jpg": case "jpeg": imagejpeg($newImage, $destination); break; case "gif": imagegif($newImage, $destination); break; case "png": imagepng($newImage, $destination); break; } } } 
+1
source share

I assume that you have some kind of thumb image queue and your application works through them? You could take a look at the siphoning of some work on something like EC2. If your queue exceeds a certain size, run a pre-prepared instance of EC2 to handle the load. You could even run several machines if the queue was massive.

You do not need these instances to run all the time - you only need them when your own server is not able to handle the load.

Obviously, you will need to predict your costs to make sure that it is worth it, but if you only pay for the time you use, and the prices start at 8.5c / hour, it can be economical enough for your needs.

+2
source share

I suggest you use ExactImage. According to the standards, it is faster than ImageMagick.

+1
source share

All Articles