Reputation: 117
I've got this custom function from DevelopPHP. For some reason it's not resizing the image to its specified size. If you see the code below, I am specifying the width ($wmax) and height ($hmax) of the image.
Below is the code that calls the function to resize the image:
$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);
This is the function that gets called by the above function:
<?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);
}
?>
Upvotes: 2
Views: 88
Reputation: 3056
Your question is vague, but you should note that that function is not designed to re-size the image to exactly 600 x 480. It is designed to scale the image to preserve the aspect ratio. In other words, it is only going to exactly match either the height you specify, or the width, but not both. Otherwise the image would be distorted or cropped.
Upvotes: 1