Jump to content


Photo

Ugly images


  • Please log in to reply
4 replies to this topic

#1 JohnLS

JohnLS
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 March 2006 - 10:46 AM

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:

//
// 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


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.

#2 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 13 March 2006 - 11:14 AM

does your server support GD2?

#3 JohnLS

JohnLS
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 March 2006 - 11:19 AM

Yes. It supports the php_gd2.dll extension.

#4 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 13 March 2006 - 11:26 AM

Look in to using imagemagick.. it's a free tool

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#5 JohnLS

JohnLS
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 March 2006 - 11:27 AM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users