Domanda

In trying to simply thumbnail an image in PHP I used:

$image = new Gmagick('/tmp/large.jpg');
$image->thumbnailImage(0, 100);
$image->writeImage('/tmp/small.jpg');

which ran in about 15 seconds.

I then tried:

exec('gm convert -size 200x100 /tmp/large.jpg -resize 200x100 +profile "*" /tmp/small.jpg');

which ran in less than one second.

Can someone explain why, in as much detail as possible? Also, are there any reasons I "shouldn't" use the second method? Or is there a way to make the gmagick extension faster?

Version details:

gmagick - 1.1.0RC3
GraphicsMagick - GraphicsMagick 1.3.17 2012-10-13 Q8

È stato utile?

Soluzione

I figured out that the '-size' option isn't part of the php thumbnailing method. Once I added it manually, the following php code actually ran slightly faster than the command line.

$image = new Gmagick();
$image->setSize(200,200);    // This sets the size of the canvas. Should be roughly twice the dimensions of the desired thumbnail for antialiasing to work well.
$image->readImage('/tmp/large.jpg');
$image->thumbnailImage(0, 100);
$image->writeImage('/tmp/small.jpg');

This post helped quite a bit.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top