ImageMagick slow Should be faster

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
dev.alex89
Posts: 12
Joined: 2011-07-03T04:02:30-07:00
Authentication code: 8675308

ImageMagick slow Should be faster

Post by dev.alex89 »

ImageMagick is slow, should be faster
check out this little test
test

This is the normal speed of execution, or are slow?

code

Code: Select all

<?php
$DOCROOT = realpath(dirname(__FILE__)).'/';
$filein   = $DOCROOT.'useruploads/userphotos/tmp/'.'dolphins.jpg'; 
$fileout  = $DOCROOT.'output/'.  uniqid().'.jpg';
   
// Command 1
$command  = '/usr/bin/convert '.escapeshellarg($filein);
$command .= ' -resize 270x265^ '.escapeshellarg($fileout);

$time_start = microtime(TRUE);
exec($command);
$time_end = microtime(true);

$time = $time_end - $time_start;
echo 'time: '.$time.'s';
?>

<br /><hr />

<?php
$file_effect = $DOCROOT.'images/effects/4e0c68cbc989311-ru-d23d5c41f769579346eddaf605cf9481.png';
$fileout  = $DOCROOT.'output/'.  uniqid().'.jpg';

// Command 2
$command = '/usr/bin/convert '.escapeshellarg($file_effect).' \( '.escapeshellarg($filein).' -resize 270x265^ -gravity center -extent 270x265 -level -10% -gravity NorthWest  -matte -virtual-pixel transparent -distort Perspective "0,0,1,1  0,265,0,264  265,0,260,72  265,260,268,236" \) -background none -geometry +177+186 -compose Atop -composite '.escapeshellarg($fileout);

$time_start = microtime(TRUE);
exec($command);
$time_end = microtime(true);

$time = $time_end - $time_start;
echo 'time: '.$time.'s';
?>
  • Server ubuntu-x86_64 500 Mhz RAM 256 Mb
    PHP Version 5.3.3-1ubuntu9.5
    ImageMagick 6.6.2-6 2010-12-02 Q16
what can I do to speed up execution?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: ImageMagick slow Should be faster

Post by Bonzo »

I would say you have a problem :?
I did some speed tests a while ago: http://www.rubblewebs.co.uk/imagemagick/notes/speed.php there is a link on the page to a more recent speed test as a pdf.

I can not try your code at the moment as I am at work.

You can speed up jpgs buy using http://www.imagemagick.org/script/comma ... php#define
jpeg:size=geometry Set the size hint of a JPEG image, for example, -define jpeg:size=128x128. It is most useful for increasing performance and reducing the memory requirements when reducing the size of a large JPEG image.
Post Reply