创建缩略图的最有效方法?

Sta*_*bie 6 php graphics imagemagick image-processing graphicsmagick

我有大量的缩略图要做.目前,我正在使用ImageMagick,但它证明效率太低(它太慢,使用太多CPU /内存等).

我已经开始评估GraphicsMagick,我希望得到"哇"的结果.我没有得到它们.有人可以快速查看我的基准脚本(仅进行简单的速度和文件大小比较;还没有CPU和内存检查):

http://pastebin.com/2gP7Eaxc

这是我得到的示例输出:

'gm convert' took 75.0039 seconds to execute 10 iteration(s).
'convert' took 83.1421 seconds to execute 10 iteration(s).
Average filesize of gm convert: 144,588 bytes.
Average filesize of convert: 81,194 bytes. 
Run Code Online (Sandbox Code Playgroud)

GraphicsMagick的速度并不快 - 输出的文件大小比ImageMagick高得多.

Chr*_*nte 1

我想用GD2,试试我用的这个功能。它非常容易使用:

function scaleImage($source, $max_width, $max_height, $destination) {
    list($width, $height) = getimagesize($source);
    if ($width > 150 || $height > 150) {
    $ratioh = $max_height / $height;
    $ratiow = $max_width / $width;
    $ratio = min($ratioh, $ratiow);
    // New dimensions
    $newwidth = intval($ratio * $width);
    $newheight = intval($ratio * $height);

    $newImage = imagecreatetruecolor($newwidth, $newheight);

    $exts = array("gif", "jpg", "jpeg", "png");
    $pathInfo = pathinfo($source);
    $ext = trim(strtolower($pathInfo["extension"]));

    $sourceImage = null;

    // Generate source image depending on file type
    switch ($ext) {
        case "jpg":
        case "jpeg":
        $sourceImage = imagecreatefromjpeg($source);
        break;
        case "gif":
        $sourceImage = imagecreatefromgif($source);
        break;
        case "png":
        $sourceImage = imagecreatefrompng($source);
        break;
    }

    imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    // Output file depending on type
    switch ($ext) {
        case "jpg":
        case "jpeg":
        imagejpeg($newImage, $destination);
        break;
        case "gif":
        imagegif($newImage, $destination);
        break;
        case "png":
        imagepng($newImage, $destination);
        break;
    }
    }
}
Run Code Online (Sandbox Code Playgroud)