我从DevelopPHP获得了此自定义函数。由于某种原因,它没有将图像调整为指定的大小。如果您看到下面的代码,则指定图像的宽度($ wmax)和高度($ hmax)。
以下是调用该函数以调整图像大小的代码:
$target_file = $location;
$fileExt = 'jpg';
$large_file = $_SERVER["DOCUMENT_ROOT"] . "/members/" . $id . "/large_" . $file_name . ".jpg";
$wmax = 600;
$hmax = 480;
ak_img_resize($target_file, $large_file, $wmax, $hmax, $fileExt);
这是上面的函数调用的函数:
<?php
// Adam Khoury PHP Image Function Library 1.0
// Function for resizing any jpg, gif, or png image files
function ak_img_resize($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
$ext = strtolower($ext);
$img = imagecreatefromjpeg($target);
$tci = imagecreatetruecolor($w, $h);
// imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
imagejpeg($tci, $newcopy, 80);
}
?>
您的问题含糊不清,但您应注意,该功能并非旨在将图像调整为恰好为600 x 480的大小。它旨在缩放图像以保持纵横比。换句话说,它只会完全匹配您指定的高度或宽度,但不能完全匹配。否则图像会失真或裁切。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句