I am having trouble in resizing the image. What I am trying to do is letting
people upload images of any dimension, and with the aid of my script after
having uploaded, it renames the file, from this new file I'll get the size
and resize it to predefined format 360x240 or 240x360 and this is the normal
presentation image (image1_big). From this image I am getting a thumb nail
format of 104x70 or 70x104 ( image1_thumb ).

When I run the script the whole page is filled with characters, I know the
first part of the script upload is working as I can see the file on the
server. The script resizing apparently is not functioning.

I ve checked the Php config at my service provider with the aid of Phpinfo()
and I can see the GD version 2.0 or higher enabled, so that question is
cleared.

I am pretty sure the error is from my sloppy code.



I'd appreciate if some one could look into my code and see where the bug is.



<?php // image_pro.php

$uploaddir='../images/repor_images/'; // Uploaded images directory on the
server

$n_image1 = $_FILES['image1']['name'];// New file before renaming it.



if // Image1

    (move_uploaded_file($_FILES['image1']['tmp_name'],
$uploaddir.$n_image1)) {

        rename($uploaddir .$n_image1, $uploaddir.time().$n_image1); //
Renames the file in the server.

         $size = GetImageSize($uploaddir.time().$n_image1);

         $width = $size[0];

         $height = $size[1];

         if ($heigth<$width){

             $newwidth = '360';

             $newheight = '240';

             header ("Content-type: image/jpeg");

             $src = imagecreatefromjpeg($uploaddir.time().$n_image1);

             $image1_big = imagecreate($newwidth,$newheight);


imagecopyresized($image1_big,$src,0,0,0,0,$newwidth,$newheight,$width,$heigh
t);

             imagejpeg($image1_big); // New normal sized image

             imagedestroy($src);// deletes the initial image

             $size_big = GetImageSize($uploaddir.$image1_big);

             $width_big = $size[0];

             $height_big = $size[1];

             $newwidth_thumb = '104';

             $newheight_thumb = '70';

             $src_thumb = imagecreatefromjpeg($uploaddir.$image1_big);

             $image1_thumb = imagecreate($newwidth_thumb,$newheight_thumb);


imagecopyresized($image1_thumb,$src_thumb,0,0,0,0,$newwidth_thumb,$newheight
_thumb,$width_big,$heigh
t_big);

             imagejpeg("tn_".$image1_thumb); // New thumbnail

         }

         elseif ($heigth>$width){

             $newwidth = '360';

             $newheight = '240';

             header ("Content-type: image/jpeg");

             $src = imagecreatefromjpeg($uploaddir.time().$n_image1);

             $image1_big = imagecreate($newwidth,$newheight);


imagecopyresized($image1_big,$src,0,0,0,0,$newwidth,$newheight,$width,$heigh
t);

             imagejpeg($image1_big); // New normal sized image

             imagedestroy($src);// deletes the initial image

             $size_big = GetImageSize($uploaddir.$image1_big);

             $width_big = $size[0];

             $height_big = $size[1];

             $newwidth_thumb = '70';

             $newheight_thumb = '104';

             $src_thumb = imagecreatefromjpeg($uploaddir.$image1_big);

             $image1_thumb = imagecreate($newwidth_thumb,$newheight_thumb);


imagecopyresized($image1_thumb,$src_thumb,0,0,0,0,$newwidth_thumb,$newheight
_thumb,$width_big,$heigh
t_big);

             imagejpeg("tn_".$image1_thumb); // New thumbnail

         }

        print "$image1_big. File transfered. <br>\n";

        print "$image1_thumb. File transfered. <br>\n";

        $image1_big_url = time().$image1_big;    // Sets the name of the
file to be Copied into the database.

        $image1_thumb_url = time()."tn_".$image1_thumb;    // Sets the name
of the file to be Copied into the database.

    }

    else {

    print "File failed to transfer!\n";

    $image1_url = "";

    exit();

    }

?>


Thanks in advance for the time and humble helping hand.



GD



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to