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);
?>
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.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
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.