If an html file is empty, pretend it has a body
[booki.git] / site_media / xinha / plugins / ImageManager / thumbs.php
blobe69fde187568c7cbd4add3207c7db3b57a46032f
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:ray $
7 * @version $Id:thumbs.php 677 2007-01-19 22:24:36Z ray $
8 * @package ImageManager
9 */
11 require_once('config.inc.php');
12 require_once('Classes/ImageManager.php');
13 require_once('Classes/Thumbnail.php');
15 //check for img parameter in the url
16 if(!isset($_GET['img']))
18 exit();
22 $manager = new ImageManager($IMConfig);
24 //get the image and the full path to the image
25 $image = rawurldecode($_GET['img']);
26 $fullpath = Files::makeFile($manager->getImagesDir(),$image);
28 //not a file, so exit
29 if(!is_file($fullpath))
31 exit();
34 $imgInfo = @getImageSize($fullpath);
36 //Not an image, send default thumbnail
37 if(!is_array($imgInfo))
39 //show the default image, otherwise we quit!
40 $default = $manager->getDefaultThumb();
41 if($default)
43 header('Location: '.$default);
44 exit();
47 //if the image is less than the thumbnail dimensions
48 //send the original image as thumbnail
50 if ($imgInfo[0] <= $IMConfig['thumbnail_width']
51 && $imgInfo[1] <= $IMConfig['thumbnail_height'])
54 header('Location: '. $manager->getFileURL($image));
55 exit();
58 //Check for thumbnails
59 $thumbnail = $manager->getThumbName($fullpath);
61 if(is_file($thumbnail))
63 //if the thumbnail is newer, send it
64 if(filemtime($thumbnail) >= filemtime($fullpath))
66 header('Location: '.$manager->getThumbURL($image));
67 exit();
71 //creating thumbnails
72 $thumbnailer = new Thumbnail($IMConfig['thumbnail_width'],$IMConfig['thumbnail_height']);
73 $thumbnailer->createThumbnail($fullpath, $thumbnail);
75 //Check for NEW thumbnails
76 if(is_file($thumbnail))
78 //send the new thumbnail
79 header('Location: '.$manager->getThumbURL($image));
80 exit();
82 else
84 //show the default image, otherwise we quit!
85 $default = $manager->getDefaultThumb();
87 if($default)
88 header('Location: '.$default);