Hi frnds...

I am going to do Image gallery...I want to upload more number of photos at a time ..any body having both design form and backend code (thumnail image, preview image into database)...plz fwd what ever u have...i can modifythe code based on my requirement....

Sry 4 asking readymade code...i am having code,but it works only 1 or 2 images at a time..

Thanks in advance...

Hi there,

I've got this code for creating thumbnails, i'm not sure if it's what you're looking for but here it is:

function createThumb($imageDirectory, $imageName, $thumbDirectory)
  {
      $ext = strtolower(substr($imageName, strrpos($imageName, '.')));
      if (($ext == "jpg") || ($ext == "jpeg"))
      {
          if(function_exists('imagecreatefromjpeg'))
          {
             $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");  
             $originalWidth = imagesx($srcImg);
            $originalHeight = imagesy($srcImg);
            $thumb_maxY_P="85";
            $thumb_maxX_P="114";
            $thumb_maxY_L="114";
            $thumb_maxX_L="85";
            $theRatio = $originalWidth / $originalHeight;
            if($theratio<1)
            {
                $newWidth=ceil($thumb_maxX_P / $theRatio);
                $newHeight=$thumb_maxY_P;
            }
            else
            {
                $newWidth =$thumb_maxX_L;
                $newHeight = ceil($thumb_maxY_L / $theRatio);
            }
            $thumbImg = imagecreatetruecolor($newWidth,$newHeight);
            imagecopyresized($thumbImg, $srcImg,0, 0, 0, 0, $newWidth, $newHeight, imagesx($srcImg), imagesy($srcImg));
            $thumbname="thumb_".$imageName;
            imagejpeg($thumbImg, "$thumbDirectory/$thumbname", 100);
          }
          else
          {
               $thumbname=$imageName;
          }   
            return $thumbname;
      } 
      else if ($ext == "gif")
      {
          if(function_exists('imagecreatefromgif'))
          {
             $srcImg = imagecreatefromgif("$imageDirectory/$imageName");  
             $originalWidth = imagesx($srcImg);
            $originalHeight = imagesy($srcImg);
            $thumb_maxY_P="85";
            $thumb_maxX_P="114";
            $thumb_maxY_L="114";
            $thumb_maxX_L="85";
            $theRatio = $originalWidth / $originalHeight;
            if($theratio<1)
            {
                $newWidth=ceil($thumb_maxX_P / $theRatio);
                $newHeight=$thumb_maxY_P;
            }
            else
            {
                $newWidth =$thumb_maxX_L;
                $newHeight = ceil($thumb_maxY_L / $theRatio);
            }
            $thumbImg = imagecreatetruecolor($newWidth,$newHeight);
            imagecopyresized($thumbImg, $srcImg,0, 0, 0, 0, $newWidth, $newHeight, imagesx($srcImg), imagesy($srcImg));
            $thumbname="thumb_".$imageName;
            imagejpeg($thumbImg, "$thumbDirectory/$thumbname", 100);
          }
          else
          {
               $thumbname=$imageName;
          }   
            return $thumbname;
      }
      else  if ($ext == "png")
      {
          if(function_exists('imagecreatefrompng'))
          {
             $srcImg = imagecreatefrompng("$imageDirectory/$imageName");  
             $originalWidth = imagesx($srcImg);
            $originalHeight = imagesy($srcImg);
            $thumb_maxY_P="85";
            $thumb_maxX_P="114";
            $thumb_maxY_L="114";
            $thumb_maxX_L="85";
            $theRatio = $originalWidth / $originalHeight;
            if($theratio<1)
            {
                $newWidth=ceil($thumb_maxX_P / $theRatio);
                $newHeight=$thumb_maxY_P;
            }
            else
            {
                $newWidth =$thumb_maxX_L;
                $newHeight = ceil($thumb_maxY_L / $theRatio);
            }
            $thumbImg = imagecreatetruecolor($newWidth,$newHeight);
            imagecopyresized($thumbImg, $srcImg,0, 0, 0, 0, $newWidth, $newHeight, imagesx($srcImg), imagesy($srcImg));
            $thumbname="thumb_".$imageName;
            imagejpeg($thumbImg, "$thumbDirectory/$thumbname", 100);
          }
          else
          {
               $thumbname=$imageName;
          }   
            return $thumbname;
      } else {
          return false;
      }
   }

Hi..

Can u explain me, how i can use it...how can i call this function to my code....plz take a simple form and explain....

Thanks in advance...

hi,
u said u are having code for uploading 1 or 2 images ,loop it for 10 times using for loop condition like

for($i=0;$i<10;$i++){
//your code to generate images and insert query too
}

it will work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.