PHP image Uploading along with thumbnail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deejam
    New Member
    • Apr 2007
    • 13

    PHP image Uploading along with thumbnail

    hi,

    i've this situations where user will upload images..my code works fine for uploading images.. but i need to create auto thumbnail picture (of the same image) whenever user upload images... help me how to create thumbnail picture..
    is my question clear?

    thk in advance
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    You can use the height and width attributes of the <img> tag to adjust the size of the image.

    Originally posted by Deejam
    hi,

    i've this situations where user will upload images..my code works fine for uploading images.. but i need to create auto thumbnail picture (of the same image) whenever user upload images... help me how to create thumbnail picture..
    is my question clear?

    thk in advance

    Comment

    • Deejam
      New Member
      • Apr 2007
      • 13

      #3
      @ Motoma

      here the page shows the all the images which user has uploaded, if i use the height and width to reduce the image display size, eventually the page will take much time to load...

      hope i'm clear...

      thkx for replying

      Comment

      • cyberking
        New Member
        • Jan 2007
        • 84

        #4
        Hi Deejam

        In that case, you can as well write your own image resizing function. Not a big deal. Get the size of the image using the getimagesize function. Store the return values in a variable. Perform reduction on the width and the height returned by the getimagesize function and then return the new reduced width and heigth to the width and height parameters in the img tag.

        More if you need help
        Regards
        CyberKing

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          Cyberking's method is valid; if you want to do more research on this method, you should look up the PHP GD functions.

          Comment

          • Deejam
            New Member
            • Apr 2007
            • 13

            #6
            Thanks cyberking and Motoma...

            here is the code for creating thumbnail to the uploading picture...

            echo "Creating thumbnail for $filename <br />";
            // Load image and get image size
            $orgimg = imagecreatefrom jpeg($filename) ;
            $width = imagesx($orgimg );
            $height = imagesy($orgimg );
            // Setting new width and height for thumbnail size
            $newwidth = 100; //any size as you wish
            $newheight = floor($height*( $newwidth/$width));
            // Creating new temporary image
            $tmpimg = imagecreatetrue color($newwidth , $newheight);
            // Copy and resize old image into new image
            imagecopyresize d($tmpimg, $orgimg, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
            // Save thumbnail into a file
            imagejpeg($tmpi mg, $path_to_thumbs _dir.$filename) ;


            i welcome any suggestion/correction...

            Comment

            Working...