Advertisement
FamiHug

php thumb

May 15th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2. function createAThumbnail ($path, $thumbPath , $fname, $thumbWidth)
  3. {
  4.     // parse path for the extension
  5.     $info = pathinfo($pathToImages . $fname);
  6.     // continue only if this is a JPEG image
  7.     if ( strtolower($info['extension']) == 'jpg' )
  8.     {
  9.       echo "Creating thumbnail for {$fname} <br />";
  10.  
  11.       // load image and get image size
  12.       $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
  13.       $width = imagesx( $img );
  14.       $height = imagesy( $img );
  15.  
  16.       // calculate thumbnail size
  17.       $new_width = $thumbWidth;
  18.       $new_height = floor( $height * ( $thumbWidth / $width ) );
  19.  
  20.       // create a new temporary image
  21.       $tmp_img = imagecreatetruecolor( $new_width, $new_height );
  22.  
  23.       // copy and resize old image into new image
  24.       imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
  25.  
  26.       // save thumbnail into a file
  27. //      phpinfo();
  28.       //echo "<img src=$thumbPath$fname>";
  29.  
  30.       $fname = "thumb_".$fname;
  31.       imagejpeg( $tmp_img, $thumbPath.$fname );
  32.       echo "created thumb";
  33.     }
  34. }//createAThumb
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement