Page 1 of 1

ImageMagick Slow Speed?

Posted: 2013-08-11T22:04:54-07:00
by iamchairs
This may be a common question and I have googled a lot but I think it's best to just ask this here.

So for my project I'm going to need to be doing a lot of image processing on the fly and I'm trying to see if ImageMagick will work for this. I tried generating to ImageMagick logos and running composite -compose plus on them.

Code: Select all

<?php
        $stime = microtime(TRUE);
        `composite -compose plus logo.png logo2.png logo3.png`;
        $etime = microtime(TRUE);

        echo "ImageMagick takes " . ($etime-$stime) . "\n";

        $stime = microtime(TRUE);
        list($w, $h) = getimagesize("logo.png");
        $img1 = imagecreatefrompng("logo.png");
        $img2 = imagecreatefrompng("logo2.png");
        $gd = imagecreatetruecolor($w, $h);

        for($r = 0; $r < $h; $r++)
        {   
                for($c = 0; $c < $w; $c++)
                {   
                        $rgb1 = imagecolorat($img1, $c, $r);
                        $r1 = ($rgb1 >> 16) & 0xFF;
                        $g1 = ($rgb1 >> 8) & 0xFF;
                        $b1 = $rgb1 & 0xFF;

                        $rgb2 = imagecolorat($img2, $c, $r);
                        $r2 = ($rgb2 >> 16) & 0xFF;
                        $g2 = ($rgb2 >> 8) & 0xFF;
                        $b2 = $rgb2 & 0xFF;

                        $_r = min($r1+$r2,255);
                        $_g = min($g1+$g2,255);
                        $_b = min($b1+$b2,255);

                        $color = imagecolorallocate($gd, $_r, $_g, $_b);
                        imagesetpixel($gd, $c, $r, $color);
                }   
        }   

        imagepng($gd, "logo3.png");

        $etime = microtime(TRUE);

        echo "GD/Raw PHP takes " . ($etime-$stime);
?>
ImageMagick takes 0.49048900604248
GD/Raw PHP takes 0.82335996627808

ImageMagick takes 0.56417179107666
GD/Raw PHP takes 0.78314518928528

ImageMagick takes 0.71494483947754
GD/Raw PHP takes 0.83449196815491

ImageMagick takes 0.56718897819519
GD/Raw PHP takes 0.73664999008179
For gifs imagemagick takes around 1.2 seconds and php takes around 0.8 seconds. For jpegs imagemagick kicks the crap out of php and only take 0.06 seconds while php takes 0.7 seconds.

So maybe I can convert pngs to jpgs, use plus, then jpgs back to pngs? Will this reduce the quality of the image?

Why isn't ImageMagick much better in all tests? I thought it was gpu accelerated.

Re: ImageMagick Slow Speed?

Posted: 2013-08-11T22:20:07-07:00
by fmw42
gifs take a lot of computation to create the optimum color table so it takes more time. see http://www.imagemagick.org/script/quantize.php

You can speed it up by using a smaller value for -tree-depth. see http://www.imagemagick.org/script/comma ... #treedepth