Hi, I have been using the following function to re size my images but to be honest i am not really happy with the end result as the images are not 100% clear. Is there anything i can do to make the images clearer? function uploadimage($value, $alwidth) { $file_type = $value['type']; $file_name = $value['name']; $file_size = $value['size']; $file_tmp = $value['tmp_name']; //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //create a random file name $rand_name = md5(time()); $rand_name= rand(0,999999999); //get the new width variable. list($ewidth, $eheight) = getimagesize($file_tmp); if ($ewidth < 175){ $ThumbWidth = $ewidth; }else{ $ThumbWidth = 175; } if ($alwidth == ''){ if ($ewidth < 600){ $ImgWidth = ($ewidth + 40); }else{ $ImgWidth = 640; } }else{ $ImgWidth = $alwidth; } if ($ewidth < 220){ $medWidth = $ewidth; }else{ $medWidth = 220; } //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $bigger = ($width >= $height) ? $width : $height; $imgratio = $bigger / $ThumbWidth; $newwidth = intval($width / $imgratio); $newheight = intval($height / $imgratio); $imgratio = $bigger / $ImgWidth; $newwidth2 = intval($width / $imgratio); $newheight2 = intval($height / $imgratio); $imgratio = $bigger / $medWidth; $newwidth3 = intval($width / $imgratio); $newheight3 = intval($height / $imgratio); $resized_img = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $resized_img2 = imagecreatetruecolor($newwidth2, $newheight2); imagecopyresized($resized_img2, $new_img, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height); $resized_img3 = imagecreatetruecolor($newwidth3, $newheight3); imagecopyresized($resized_img3, $new_img, 0, 0, 0, 0, $newwidth3, $newheight3, $width, $height); imagejpeg($resized_img, "imgtemp/thumbs/".$rand_name.".".$file_ext); imagejpeg($resized_img2, "imgtemp/big/".$rand_name.".".$file_ext); imagejpeg($resized_img3, "imgtemp/med/".$rand_name.".".$file_ext); //save images ftpupload($rand_name.".".$file_ext, "imgtemp/thumbs/".$rand_name.".".$file_ext, "/httpdocs/uploads/images/thumbs/"); ftpupload($rand_name.".".$file_ext, "imgtemp/big/".$rand_name.".".$file_ext, "/httpdocs/uploads/images/big/"); ftpupload($rand_name.".".$file_ext, "imgtemp/med/".$rand_name.".".$file_ext, "/httpdocs/uploads/images/med/"); unlink("imgtemp/big/".$rand_name.".".$file_ext); unlink("imgtemp/thumbs/".$rand_name.".".$file_ext); unlink("imgtemp/med/".$rand_name.".".$file_ext); imagedestroy($resized_img); imagedestroy($resized_img2); imagedestroy($resized_img3); imagedestroy($new_img); } $value = $rand_name.".".$file_ext; return $value; } PHP: Cheers, Adam
Try to add quality parameter for your 'imagejpeg' functions: imagejpeg ( resource $image [, string $filename [, int $quality ]] ) - default if about 75, set to 100. imagejpeg($resized_img, "imgtemp/thumbs/".$rand_name.".".$file_ext, 100); imagejpeg($resized_img2, "imgtemp/big/".$rand_name.".".$file_ext, 100); imagejpeg($resized_img3, "imgtemp/med/".$rand_name.".".$file_ext, 100);
why struggle with this, instead use a free php image library. check this out: http://best-php-scripts.com/image_manipulation.htm i often use php thumbnailer class to do cutting and resizing.
well, if this is for study purposes then it defeats the idea, but if indeed you just want to process your images then you're better off with imagemagick and other ready made libraries
I tried this but did not make a difference so looks like it is set to 100% already. Is there anything else i can do at all to this. Thanks for the suggestions about using e.g. imagemagick but i want to stick with the current function.