PHP thumbnail help

Post everything else here

Moderators: Website/Forum Admins, Other/Off Topic Moderators

khawarikhan
Posts: 1
Joined: Wed Jul 28, 2004 9:41 pm
Contact:

PHP thumbnail help

Postby khawarikhan » Wed Jul 28, 2004 10:44 pm

Can someone please help me with a little problem I am having. I want to generate thumbnails for the images uploaded on my site. I want to auto generate the thumbnail for the images that I upload to my site. In the admin area for my site, I have an option to upload image for my products. Now, rahter than converting the image to the thumbnail manually using somesoftware and then upload both image & its thumbnail, I want to upload the image only to the PHP site and the code will generate the thumnail for me. Thanks for your help!!!!!!!

Khawar
User avatar
Pills
Forum Admin
Posts: 312
Joined: Wed Jul 02, 2003 1:14 pm
Location: Long Island, NY
Contact:

Postby Pills » Thu Jul 29, 2004 3:01 am

As this has nothing to do with EFnet, moved to Off-Topic.
admin, irc.umich.edu
oper, irc.servercentral.net
User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Thu Jul 29, 2004 7:39 pm

i'll leave it to you to fill in the gaps, but this is how we do thumbnailing:

Code: Select all

    if($_SERVER['REQUEST_METHOD']=='POST')
    {
      $LARGE_IMG_SIZE = 320;
      $SMALL_IMG_SIZE = 96;
      error_reporting(53);
      $acceptedTypes = array('image/jpeg', 'image/jpg', 'image/pjpeg');
      if(in_array($_FILES['user_img']['type'], $acceptedTypes) && trim($_FILES['user_img']['tmp_name']) != "")
      {
        $img_orig_size = getimagesize($_FILES['user_img']['tmp_name']);
        $img_orig_width = $img_orig_size[0];
        $img_orig_height = $img_orig_size[1];

        $img_original = ImageCreateFromJpeg($_FILES['user_img']['tmp_name']);
        $image_stored = $_SESSION['user_id'];

        print "$img_orig_width $img_orig_height $image_stored<br>";
        if($img_orig_width > $LARGE_IMG_SIZE || $img_orig_height > $LARGE_IMG_SIZE)
        {
          $mlt_w = $LARGE_IMG_SIZE / $img_orig_width;
          $mlt_h = $LARGE_IMG_SIZE / $img_orig_height;
          $mlt = $mlt_w < $mlt_h ? $mlt_w : $mlt_h;
          $img_new_width = round($img_orig_width * $mlt);
          $img_new_height = round($img_orig_height * $mlt);

          $img_resized = imagecreatetruecolor($img_new_width, $img_new_height);
          imagecopyresampled($img_resized, $img_original, 0 , 0 , 0 , 0, $img_new_width, $img_new_height, $img_orig_width, $img_orig_height);

          $BIGimg_name = $image_stored."l.jpg";
          Imagejpeg($img_resized, "$IMG_ROOT/$BIGimg_name");
        }
        else
        {
          $BIGimg_name = $image_stored."l.jpg";
          Imagejpeg($img_original, "$IMG_ROOT/$BIGimg_name");
        }

        if($img_orig_width > 96 || $img_orig_height > 96)
        {
          $mlt_w = $SMALL_IMG_SIZE / $img_orig_width;
          $mlt_h = $SMALL_IMG_SIZE / $img_orig_height;
          $mlt = $mlt_w < $mlt_h ? $mlt_w : $mlt_h;
          $img_new_width = round($img_orig_width * $mlt);
          $img_new_height = round($img_orig_height * $mlt);

          $img_resized = imagecreatetruecolor($img_new_width, $img_new_height);
          imagecopyresampled($img_resized, $img_original, 0 , 0 , 0 , 0, $img_new_width, $img_new_height, $img_orig_width, $img_orig_height);

          $SMALLimg_name = $image_stored."s.jpg";
          Imagejpeg($img_resized, "$IMG_ROOT/$SMALLimg_name");
        }
        else
        {
          $SMALLimg_name = $image_stored."s.jpg";
          Imagejpeg($img_original, "$IMG_ROOT/$SMALLimg_name");
        }
        ImageDestroy($img_resized);
      }
In God we trust,
Everyone else must have an X.509 certificate.

Who is online

Users browsing this forum: No registered users and 2 guests