thumbs.php 1.9 KB

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