无需裁剪即可在 1280x 720 上调整大量图像的大小

问题描述

我在 jpg 文件夹中有 60 个 img 图片
它们都是不同的维度
需要所有这些都是 1280 x 720
白色背景 - 如果需要
页面上使用此代码微调器可以运行 10 秒 - 这意味着代码可以运行 - 但最终结果是 - 什么都没有
每个图像的尺寸都与之前相同
请帮忙

function resize_no_crop($el,$w,$h) {
    list($width,$height) = getimagesize($el);
    $r = $width / $height;
    if ($w/$h > $r) {
        $newwidth = $h*$r;
        $newheight = $h;
    } else {
        $newheight = $w/$r;
        $newwidth = $w;
    }
    $src = imagecreatefromjpeg($el);
    $dst = imagecreatetruecolor($newwidth,$newheight);
    imagecopyresampled($dst,$src,$newwidth,$newheight,$width,$height);
    return $dst;
}

$arr = glob('img/*');
foreach($arr as $el){resize_no_crop($el,1280,720);}
echo 'finito';

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)