Friday, February 26, 2010

Create thumbnail image in php

This function will create the thumbnail image of the source file
other thing explain in function

function createthumbimage($source_path,$ext,$filename)
    {

          //$ext=extension of file

      
     if ($ext == 'jpg' || $ext == 'jpeg')
     {
      $img = @imagecreatefromjpeg($source_path);
     }
      else if ($ext == 'png')
      {
      $img = @imagecreatefrompng($source_path);
     # Only if your version of GD includes GIF support
     } else if ($ext == 'gif')
     {
      $img = @imagecreatefromgif($source_path);
     }
    
         if ($img)
     {

      # Get image size and scale ratio
      $width = imagesx($img);
      $height = imagesy($img);
      $scale = min(PRODUCT_MAX_WIDTH/$widthPRODUCT_MAX_WIDTH/$height);
     //PRODUCT_MAX_WIDTH and PRODUCT_MAX_WIDTH is predefine width and height of thumbnail image

      # If the image is larger than the max shrink it
     
       $new_width = floor($scale*$width);
       $new_height = floor($scale*$height);
    
       # Create a new temporary image
       $tmp_img = imagecreatetruecolor($new_width, $new_height);
    
       # Copy and resize old image into new image
       imagecopyresized($tmp_img, $img, 0, 0, 0, 0,
            $new_width, $new_height, $width, $height);
       imagedestroy($img);
       $img = $tmp_img;
    
      // $new_filename="";
       imagejpeg($img,PRODUCT_IMG_THUMB_PATH.$filename);

         // PRODUCT_IMG_THUMB_PATH.= this the define path that will put thumb file in define path

      }
   }

Have Dream Day

Tuesday, February 16, 2010

Get file extension in php

The file extension with all details can get below given way


/*** example usage ***/$filename 'filename.blah.txt';//this is file name or any file also can uploaded
/*** get the path info ***/$info pathinfo($filename);//
/*** show the extension ***/echo $info['extenstion'];//
?>

Friday, February 12, 2010

Mysql dump Table for all countries and states

Hi
      This the MySQL dump file contains the list of all country and state respectively,
for that just create the database and import the file.
 Attechment

Have Dream Day