【问题标题】:Resize image without lose quality when image is bigger then 3000px当图像大于 3000 像素时调整图像大小而不损失质量
【发布时间】:2012-05-22 16:58:27
【问题描述】:

我有脚本可以在不损失质量的情况下调整上传图片的大小,但是当它的宽度/高度超过 3000 像素时,它不会调整大小。我尝试在 httaccess 中设置值,但没有任何变化。

这是脚本:

$filename = "image.jpg";
    // Set a maximum height and width
    $width = 490;
    $height = 800;

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

    list($width_orig, $height_orig) = getimagesize($filename);

    $ratio_orig = $width_orig / $height_orig;

    if ($width / $height > $ratio_orig) {
        $width = $height * $ratio_orig;
    } else {
        $height = $width / $ratio_orig;
    }

    // Resample
    $image_p = imagecreatetruecolor($width, $height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

    // Output
    imagejpeg($image_p, "image_resized.jpg", 100);



我尝试过的 .htacces:

php_value memory_limit 24M
php_value upload_max_filesize 10M  
php_value post_max_size 10M  
php_value max_input_time 300  
php_value max_execution_time 300 

【问题讨论】:

  • 白屏没有图片,没有别的,图片是上传的,但是是原始大小
  • 你可以试试var_dump(imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig));exit; 来检查返回值吗?

标签: php


【解决方案1】:

在重新采样图像时使用@

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = @imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

经过测试的解决方案。

【讨论】:

    猜你喜欢
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多