PHP通过多个图像减小尺寸和质量

时间:2015-12-05 18:15:41

标签: php image image-resizing

此功能仅适用于一张照片。该功能仅在我调用该函数一次时才有效。

function imgToThumbnail($name) {
    $filename = $name;
    $percent = 0.05;

    header('Content-Type: image/jpeg');

    list($width, $height) = getimagesize($filename);
    $new_width = $width * $percent;
    $new_height = $height * $percent;

    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    $thumbnail=imagejpeg($image_p, null, 90);

    imagedestroy($image_p);
    return $thumbnail;
}

imgToThumbnail("01.jpg"); // ok
imgToThumbnail("02.jpg"); // not working

我忘记了什么?

0 个答案:

没有答案