JohnLS Posted March 13, 2006 Share Posted March 13, 2006 Hi there. Im new here and a bit desperate.I own a website with images (covers) and we use a script to resize the images to a smaller preview and an even smaller thumbnail.But something goes wrong. The resizes are ugly. I dont know what we did wrong and we can find the solution. So I thought to copy the script here and prey for help.When you want to see the resized images, visit www.vendettta.nl. You can see the ugly thumbs on the homepage but for the previews you must be registered. But the thumbs speak enough.This is the script we used:[code]//// Start session management//$userdata = session_pagestart($user_ip, PAGE_INDEX);init_userprefs($userdata);//// End session management//include("class_functions.php"); $dbh2 = mysql_connect("localhost", "vendettta2", "uadmdcku") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db("vendettta_vendettta", $dbh2); if($userdata["session_logged_in"]){ if(isset($_POST["upload"])) { if(strtolower(substr($_POST['naam'], 0, 3)) == "the") { $naamcover = substr($_POST['naam'], 4) . ", The"; } else { $naamcover = $_POST['naam']; } //bestand uploaden $uploaddir = "uploads/origineel/"; $pathinfo = pathinfo('/path/to/picture.jpeg'); $extensie = $pathinfo['extension']; $_filename = md5(preg_replace("#^(.*)\.[A-Za-z\.]+$#", "\\1", basename($_FILES['upfile']['name']))); $filename= $_filename . "." .$extensie; $uploadfile = $uploaddir . $filename; while(file_exists($uploadfile)) { $filename= $_filename . $i ."." .$extensie; $uploadfile = $uploaddir . $filename; $i = $i+1; } if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)){ chmod($uploadfile, 0644); }else{ print("File upload failure<br>"); } // zoek afmetingen list($width, $height) = getimagesize($uploadfile); $i = 2; while (check_covername($naamcover) == 1) { if($i>2) { $naamcover = substr($naamcover, 0, -3) . "[".$i."]"; $i += 1; } else { $naamcover = $naamcover . "[".$i."]"; $i += 1; } } //SQL $sql = "INSERT INTO `Covers` ( `CID` , `CNaam` , `CBestand` , `COrigineelnaam`, `CResolutieH` , `CResolutieW` , `CDatum` , `CBeschrijving` , `CBekeken` , `CProgramma` , `CBeoordeling1` , `CBeoordeling2` , `CDoor` , `CToegelaten`,`CUserEmail` ) VALUES ( '', '". $naamcover ."', '". $uploadfile ."', '".$_FILES['upfile']['name']."','". $height ."', '". $width ."', '". date('Y-m-d') ."', '".$_POST['beschrijving']."', '1', '".$_POST['met']."', '0', '0', '".$userdata['username']."', '0', '".$userdata['user_email']."' )"; $result = mysql_query($sql, $dbh2) or die("query mislukt"); $sql12 = "SELECT * FROM Covers WHERE CNaam = '".$naamcover."' LIMIT 1"; $result12 = mysql_query($sql12) or die("query mislukt ".$naamcover); $array12 = mysql_fetch_assoc($result12); $image = $array12['CBestand']; $dir = ""; //Preview aanmaken // // Eerst afbeelding resizen op 800*xxx // Dan watermark overlayen // // // // // Set offset from bottom-right corner $w_offset = 0; $h_offset = 0; $extension = strtolower(substr($image, strrpos($image, ".") + 1)); // Load image from file switch ($extension) { case 'jpg': $background = imagecreatefromjpeg($dir . $image); break; case 'jpeg': $background = imagecreatefromjpeg($dir . $image); break; case 'png': $background = imagecreatefrompng($dir . $image); break; case 'gif': $background = imagecreatefromgif($dir . $image); break; default: die("Image is of unsupported type."); } // Find base image size $swidth = $array12['CResolutieW']; $sheight = $array12['CResolutieH']; // Turn on alpha blending imagealphablending($background, true); // Create overlay image $overlay = imagecreatefrompng("images/overlay.png"); // Get the size of overlay $owidth = imagesx($overlay); $oheight = imagesy($overlay); // Overlay watermark $final = imagecreatetruecolor(800, (800/$swidth)*$sheight); imagecopyresized($final, $background,0,0,0,0, 800, (800/$swidth)*$sheight, $swidth, $sheight); // Turn on alpha blending imagealphablending($final, true); imagecopy($final, $overlay, 0, 0, 0, 0, $owidth, $oheight); imagepng($final, "uploads/preview/".$array12['CID'].".png"); // Thumb maken // // // $final_thumb = imagecreatetruecolor(160, (160/$swidth)*$sheight); imagecopyresized($final_thumb, $background,0,0,0,0, 160, (160/$swidth)*$sheight, $swidth, $sheight); imagepng($final_thumb, "uploads/thumbs/".$array12['CID']."_thumb.png"); //body[/code]It's only the resizes that couse the problem. The sourcefile is OK.I hope that someone sees the problem. We are pretty desperate.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/4816-ugly-images/ Share on other sites More sharing options...
Hooker Posted March 13, 2006 Share Posted March 13, 2006 does your server support GD2? Quote Link to comment https://forums.phpfreaks.com/topic/4816-ugly-images/#findComment-16945 Share on other sites More sharing options...
JohnLS Posted March 13, 2006 Author Share Posted March 13, 2006 Yes. It supports the php_gd2.dll extension. Quote Link to comment https://forums.phpfreaks.com/topic/4816-ugly-images/#findComment-16947 Share on other sites More sharing options...
keeB Posted March 13, 2006 Share Posted March 13, 2006 Look in to using imagemagick.. it's a free tool Quote Link to comment https://forums.phpfreaks.com/topic/4816-ugly-images/#findComment-16949 Share on other sites More sharing options...
JohnLS Posted March 13, 2006 Author Share Posted March 13, 2006 Yes, it supports the php_gd2.dll extension.*Whoops! Doublepost*Imagemagick. Means I need to rewrite the whole script?Euh... would you help me with that? Quote Link to comment https://forums.phpfreaks.com/topic/4816-ugly-images/#findComment-16950 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.