I have a function that dynamically resizes images that have been uploaded and it used to work great, however I think the host may have changed something and now the image quality is horrible (still okay on some images). I'm not sure what I can do to make this take uploaded images, resize them, and save them cleanly. Right now what's happening is the color is off or they get blotchy). Here's the function
function jpgresize ( $srcfile, $dsrd_width, $dsrd_height, $upload_dir, $dsrd_img_name ) {
//function written for using a form to upload an image
list($imagew, $imageh, $type, $attrib) = getimagesize($srcfile); // get variables for image width and height
// check image size to make sure it's under desired width x desired height
if((($imagew > $dsrd_width) || ($imageh > $dsrd_height)) && ($type == "2")) { // image width or height is greater than what you want
if($imageh > $imagew) {
$ratio = ($imageh/$imagew);
$new_h = $dsrd_height;
$new_w = ($new_h/$ratio);
}
if($imagew > $imageh) {
$ratio = ($imagew / $imageh);
$new_w = $dsrd_width;
$new_h = ($new_w/$ratio);
}
if($imagew == $imageh) {
$ratio = "1";
$new_w = $dsrd_height;
$new_h = $dsrd_height;
}
$dst_img=ImageCreate($new_w,$new_h);
$src_img=ImageCreateFromJpeg($srcfile);
ImageCopyResampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
$newfilename1 = "$upload_dir/$dsrd_img_name";
ImageJpeg($dst_img, $newfilename1);
} else { //image wasn't too big (or was format other than jpeg)... upload as normal
copy($srcfile, "$upload_dir/$dsrd_img_name");
}
}
BTW, all the images being uploaded are .jpg's, but if you have suggestions on making it more "global" for other images, i'm interested also.
Thanks
Cgraz