php resize

Status
Not open for further replies.

Chris2k

Banned
Banned
901
2009
17
0
hi

ive coded with help an php image resize code, to go in upload.php, ill show:

PHP:
include"imagecfg.php";

        //Make a 90x90px thumbnail......
        $fulluploadlPath = $thumbDir.$name;
        
        $img = imagecreatefromjpeg($fulluploadlPath);
        $img = imagecreatefrompng($fulluploadlPath);
        $img = imagecreatefromgif($fulluploadlPath);
        
        if (!$img) { echo "<h1>Error: Couldn't open image to create thumbnail!</h1>" ; }
        
            else {
                    $newW = round(($thumbPixels / $height) * $width); //thumnail width
                    $newImg = imagecreatetruecolor ($newW, $thumbPixels);
                    imagecopyresampled ($newImg, $img, 0, 0, 0, 0, $newW, $thumbPixels, $width, $height);
                    $thumbfilename = $thumbDir .'/'. $thumbName;
                    
                    imagejpeg($newImg, $thumbnName) or die("<h1>Error: Couldn't save thumnbail!</h1>");
                    
                    echo "<img src='$thumbName'>" ;
                }

can any1 help me fix these errors:

Code:
[B]Warning[/B]:  imagecreatefromjpeg(images/thumbs/1310586947.png) [[URL="http://localhost/function.imagecreatefromjpeg"]function.imagecreatefromjpeg[/URL]]: failed to open stream: No such file or directory in [B]C:\wamp\www\includes\imageupload.php[/B] on line [B]28[/B]

[B]Warning[/B]:  imagecreatefrompng(images/thumbs/1310586947.png) [[URL="http://localhost/function.imagecreatefrompng"]function.imagecreatefrompng[/URL]]: failed to open stream: No such file or directory in [B]C:\wamp\www\includes\imageupload.php[/B] on line [B]29[/B]

[B]Warning[/B]:  imagecreatefromgif(images/thumbs/1310586947.png) [[URL="http://localhost/function.imagecreatefromgif"]function.imagecreatefromgif[/URL]]: failed to open stream: No such file or directory in [B]C:\wamp\www\includes\imageupload.php[/B] on line [B]30

Thx
[/B]
 
11 comments
i notoced tht as soon as i posted:

$fulluploadlPath = $thumbDir.$name is the thumb dir to save the thumbs in.

so i change to:
$fulluploadlPath = $uploadDir.'/'.$name;

now the page isnt even displayin since i change.

ideas?

Ps: Im using wamp to prepare the script.
 
my stupid mistake, $thumbDir is the thumb directory, i needed $uploadDir...

anyways i changed it, now im getting parse error on tis line:

PHP:
        $fulluploadlPath = $uploadDir.'/' $name;

plz help.
 
Code:
[COLOR=#000000][COLOR=#0000BB]$fulluploadlPath [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$uploadDir[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]'/'.[/COLOR][COLOR=#0000BB]$name[/COLOR][COLOR=#007700];
[/COLOR][/COLOR]
 
Thanks Guys.

but now my site wont load, i added:

$fulluploadlPath = $uploadDir . '/' . $name;

and now i getP:









The connection to the server was reset while the page was loading.
 
Lol, try restarting your server?

EDIT: After the line above $fulluploadpath.....

Add these two lines and tell us the output:
PHP:
echo $fulluploadlPath;
exit();
 
ok this works:

PHP:
        $fulluploadlPath = ($uploadDir . '/' . $name); 
        echo $fulluploadlPath;
exit();

it shows the dir: images/18297627.png which is ok...............

notice $fulluploadlPath = ($uploadDir . '/' . $name); i added (), when i remove the echo i get;

The connection to the server was reset while the page was loading.
 
ok the above code is use less and dont work, 4 me anyway...

ive re written it, here we go:

PHP:
               include"imagecfg.php";

        //Make a 90x90px thumbnail......
        $fileURL = ($uploadDir . '/' . $name);
        // echo $fileURL;
        
        if ($type == "image/pjpeg" || $type == "image/jpeg") { $newThumbImg = imagecreatefromjpeg($fileURL); }
        
        if ($type == "image/x-png" || $type == "image/png") { $newThumbImg = imagecreatefrompng($fileURL); }
        
        if ($type == "image/gif") { $newThumbImg = imagecreatefromgif($fileURL); }
        
        $ratio = $width / $height; // calculate the ratio

        if ($ratio > 1 ) {
        
            $newW = $thumbPixels;
            $newH = $thumbPixels / $ratio;
    } else {
            
            $newH = $thumbPixels;
            $newW = $thumbPixels * $ratio;
    }
    
    //function for resize image.

    if (function_exists(imagecreatetruecolor)){

            $newImg = imagecreatetruecolor($newW, $newH);
    } else {

            die("Error: Please make sure you have GD library ver 2+");
    }

    //the resizing is going on here!

    imagecopyresized($newImg, $newThumbImg, 0, 0, 0, 0, $newW, $newH, $width, $height);

    //finally, save the image

[B]    ImageJpeg ($newImg $thumbDir "$newThumbImg");[/B]

    ImageDestroy ($newImg);
    ImageDestroy ($newThumbImg);

ive made it bold where im getting a parse error, can u help?
 
Status
Not open for further replies.
Back
Top