Source for file thumbs.php

Documentation is available at thumbs.php

  1. <?php
  2. /**
  3.  * On the fly Thumbnail generation.
  4.  * Creates thumbnails given by thumbs.php?img=/relative/path/to/image.jpg
  5.  * relative to the base_dir given in config.inc.php
  6.  * @author $Author$
  7.  * @version $Id$
  8.  * @package ImageManager
  9.  */
  10.  
  11. require_once('config.inc.php');
  12. require_once('Classes/ImageManager.php');
  13. require_once('Classes/Thumbnail.php');
  14.  
  15. //check for img parameter in the url
  16. if(!isset($_GET['img']))
  17.     exit();
  18.  
  19.  
  20. $manager new ImageManager($IMConfig);
  21.  
  22. //get the image and the full path to the image
  23. $image rawurldecode($_GET['img']);
  24. $fullpath Files::makeFile($manager->getBaseDir(),$image);
  25.  
  26. //not a file, so exit
  27. if(!is_file($fullpath))
  28.     exit();
  29.  
  30. $imgInfo @getImageSize($fullpath);
  31.  
  32. //Not an image, send default thumbnail
  33. if(!is_array($imgInfo))
  34. {
  35.     //show the default image, otherwise we quit!
  36.     $default $manager->getDefaultThumb();
  37.     if($default)
  38.     {
  39.         header('Location: '.$default);
  40.         exit();
  41.     }
  42. }
  43. //if the image is less than the thumbnail dimensions
  44. //send the original image as thumbnail
  45. if ($imgInfo[0<= $IMConfig['thumbnail_width']
  46.  && $imgInfo[1<= $IMConfig['thumbnail_height'])
  47.  {
  48.      header('Location: '.$manager->getFileURL($image));
  49.      exit();
  50.  }
  51.  
  52. //Check for thumbnails
  53. $thumbnail $manager->getThumbName($fullpath);
  54. if(is_file($thumbnail))
  55. {
  56.     //if the thumbnail is newer, send it
  57.     if(filemtime($thumbnail>= filemtime($fullpath))
  58.     {
  59.         header('Location: '.$manager->getThumbURL($image));
  60.         exit();
  61.     }
  62. }
  63.  
  64. //creating thumbnails
  65. $thumbnailer new Thumbnail($IMConfig['thumbnail_width'],$IMConfig['thumbnail_height']);
  66. $thumbnailer->createThumbnail($fullpath$thumbnail);
  67.  
  68. //Check for NEW thumbnails
  69. if(is_file($thumbnail))
  70. {
  71.     //send the new thumbnail
  72.     header('Location: '.$manager->getThumbURL($image));
  73.     exit();
  74. }
  75. else
  76. {
  77.     //show the default image, otherwise we quit!
  78.     $default $manager->getDefaultThumb();
  79.     if($default)
  80.         header('Location: '.$default);
  81. }
  82. ?>

Documentation generated on Mon, 05 May 2008 16:23:17 +0400 by phpDocumentor 1.4.0