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 | { |
---|
18 | exit(); |
---|
19 | } |
---|
20 | |
---|
21 | |
---|
22 | $manager = new ImageManager($IMConfig); |
---|
23 | |
---|
24 | //get the image and the full path to the image |
---|
25 | $image = rawurldecode($_GET['img']); |
---|
26 | $fullpath = Files::makeFile($manager->getImagesDir(),$image); |
---|
27 | |
---|
28 | //not a file, so exit |
---|
29 | if(!is_file($fullpath)) |
---|
30 | { |
---|
31 | exit(); |
---|
32 | } |
---|
33 | |
---|
34 | $imgInfo = @getImageSize($fullpath); |
---|
35 | |
---|
36 | //Not an image, send default thumbnail |
---|
37 | if(!is_array($imgInfo)) |
---|
38 | { |
---|
39 | //show the default image, otherwise we quit! |
---|
40 | $default = $manager->getDefaultThumb(); |
---|
41 | if($default) |
---|
42 | { |
---|
43 | header('Location: '.$default); |
---|
44 | exit(); |
---|
45 | } |
---|
46 | } |
---|
47 | //if the image is less than the thumbnail dimensions |
---|
48 | //send the original image as thumbnail |
---|
49 | |
---|
50 | if ($imgInfo[0] <= $IMConfig['thumbnail_width'] |
---|
51 | && $imgInfo[1] <= $IMConfig['thumbnail_height']) |
---|
52 | { |
---|
53 | |
---|
54 | header('Location: '. $manager->getFileURL($image)); |
---|
55 | exit(); |
---|
56 | } |
---|
57 | |
---|
58 | //Check for thumbnails |
---|
59 | $thumbnail = $manager->getThumbName($fullpath); |
---|
60 | |
---|
61 | if(is_file($thumbnail)) |
---|
62 | { |
---|
63 | //if the thumbnail is newer, send it |
---|
64 | if(filemtime($thumbnail) >= filemtime($fullpath)) |
---|
65 | { |
---|
66 | header('Location: '.$manager->getThumbURL($image)); |
---|
67 | exit(); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | //creating thumbnails |
---|
72 | $thumbnailer = new Thumbnail($IMConfig['thumbnail_width'],$IMConfig['thumbnail_height']); |
---|
73 | $thumbnailer->createThumbnail($fullpath, $thumbnail); |
---|
74 | |
---|
75 | //Check for NEW thumbnails |
---|
76 | if(is_file($thumbnail)) |
---|
77 | { |
---|
78 | //send the new thumbnail |
---|
79 | header('Location: '.$manager->getThumbURL($image)); |
---|
80 | exit(); |
---|
81 | } |
---|
82 | else |
---|
83 | { |
---|
84 | //show the default image, otherwise we quit! |
---|
85 | $default = $manager->getDefaultThumb(); |
---|
86 | |
---|
87 | if($default) |
---|
88 | header('Location: '.$default); |
---|
89 | } |
---|
90 | ?> |
---|