Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2002
    Location
    UK
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts

    A Little GD problem with image re-sizing

    Ok i'm trying to upload an image, save it and save a thumbnail image too. Now heres the first bit i've done which will just save it as a thumbnail but its not working :S can anyone suggest what i've done wrong ?

    PHP Code:
    <?php

    if (isset($_POST["Submit"]))
    {
            
    $path "/images";
            
    $size_w 100;
            
    $size_h 75;

            
    header("Content-type: image/jpeg");
            
    $src_img ImageCreateFromJpeg($_FILES["upload"]);
            
    $dst_img ImageCreate($size_w$size_h);
            
    imagecopyresized($dst_img$src_img0000$size_w$size_hImageSX($src_img),ImageSY($src_img));
            
    Imagejpeg($dst_img$path100);
    }
    else
    {
    ?>

    <form name="form1" enctype="multipart/form-data" method="post" action="<?PHP $PHP_SELF?>">
      <input name="upload" type="file" id="upload">
      <input type="submit" name="Submit" value="Submit">
    </form>

    <?php
    }    

    ?>
    oh one more thing. I'm currently having to develop this on my hosts web server as i can't get GD working in PHP on my localhost any ideas on that too ?

    Thanx

    Stu

  • #2
    Registered User
    Join Date
    Feb 2003
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey

    I think GD is installed on firepages package

    http://www.firepages.com.au/

    Jesh

  • #3
    New Coder
    Join Date
    Sep 2002
    Location
    UK
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i don't actually want to install an entire package thing i just need to know how to setup GD on a windows box thats all.

    But more importantly why the above script is producing an error when its run on a server with GD installed?

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    with your inline script you'd probably get issues with headers - attempting to send a http header after an image one would glitch - might be ok as no browser output is really sent - iffy though.

    also, referencing the resource file as $_FILES['upload'] isn't enough. Until you move it from /tmp/ it would be refered to as $_FILES['upload']['tmp_name'] though I suggest you move it from /tmp/ prior to thumbnailing it

    so....

    {
    move_uploaded_file($_FILES['upload']['tmp_name'],'folder/newname.jpg');
    $path = "/images";
    $size_w = 100;
    $size_h = 75;

    ob_start();
    header("Content-type: image/jpeg");
    $src_img = ImageCreateFromJpeg('folder/newname.jpg');
    $dst_img = ImageCreate($size_w, $size_h);
    imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $size_w, $size_h, ImageSX($src_img),ImageSY($src_img));
    Imagejpeg($dst_img, $path, 100);
    ob_end_clean();
    }

    Also - type test before moving, size test before moving, just do all you can to assure the uploaded file is exactly what you want.
    Note: you'd probably want to create a name for the uploaded image based on other params.

    Last note: ImageCreate (certainly within old builds of GD) is limited to a 256 colour palette. If you have GD2+ use imagecreatetruecolor and imagecopyresampled - else scamper over to sitepoint and search for a php tut on GD
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One last note:

    ImageJPEG($dst_img, $path, 100);

    would effectively try to save the thumb as /images

    perhaps

    ImageJPEG($dst_img,$path.'/file.jpg',80);

    would be better.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •