4

在尝试简单地在 PHP 中对图像进行缩略图时,我使用了:

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

它在大约 15 秒内运行。

然后我尝试了:

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

它在不到一秒钟的时间内运行。

有人可以尽可能详细地解释原因吗?另外,我“不应该”使用第二种方法有什么原因吗?或者有没有办法让 gmagick 扩展更快?

版本详情:

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

4

1 回答 1

1

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.

于 2012-12-06T18:50:22.260 回答