我正在尝试使用 WideImage 库调整上传图像的大小。
我需要将其转换为可能的最高分辨率。输出大小应为 Width:460px Height:345px
这是我调整大小的来源:
list($w, $h) = getimagesize($_FILES['image']['tmp_name']);
$wpercent = ($w/460)*100;
$hpercent = ($h/345)*100;
if ($wpercent >= 100 && $hpercent >= 100) {
// Both is over 100% of the allowed size, then resize so the smaller side match.
if ($wpercent > $hpercent) {
// height is smallest
$remove_percent = $hpercent - 100;
}else{
// width is smallest
$remove_percent = $wpercent - 100;
}
$new_h_percent = $hpercent - $remove_percent;
$new_w_percent = $wpercent - $remove_percent;
$new_w = ($w/460)*$new_w_percent;
$new_h = ($h/345)*$new_h_percent;
$img = $img->resize($new_w, $new_h, 'inside');
$img = $img->crop("center", "middle", 460, 345);
}else {
// En af dem er for små
if ($wpercent > $hpercent) {
// height is smallest
$add_percent = 100 - $hpercent;
}else{
// width is smallest
$add_percent = 100 - $wpercent;
}
$new_h_percent = $hpercent + $add_percent;
$new_w_percent = $wpercent + $add_percent;
$new_w = ($w/460)*$new_w_percent;
$new_h = ($h/345)*$new_h_percent;
$img = $img->resize($new_w, $new_h, 'inside');
$img = $img->crop("center", "middle", 460, 345);
}
$img->saveToFile('uploads/tmp/'.$new_name);
它确实会调整大小,只是缩小到我想要的大小。
有任何想法吗?
如果需要,它也应该裁剪。