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 | * Authors: Wei Zhuo, Afru, Krzysztof Kotowicz
|
---|
7 | * Version: Updated on 08-01-2005 by Afru
|
---|
8 | * Version: Updated on 21-06-2006 by Krzysztof Kotowicz
|
---|
9 | * Package: ExtendedFileManager (EFM 1.1.1)
|
---|
10 | * http://www.afrusoft.com/htmlarea
|
---|
11 | */
|
---|
12 | if(isset($_REQUEST['mode'])) $insertMode=$_REQUEST['mode'];
|
---|
13 | if(!isset($insertMode)) $insertMode="image";
|
---|
14 |
|
---|
15 | require_once('config.inc.php');
|
---|
16 | require_once('Classes/ExtendedFileManager.php');
|
---|
17 | require_once('../ImageManager/Classes/Thumbnail.php');
|
---|
18 |
|
---|
19 | //check for img parameter in the url
|
---|
20 | if(!isset($_GET['img']))
|
---|
21 | exit();
|
---|
22 |
|
---|
23 | $manager = new ExtendedFileManager($IMConfig,$insertMode);
|
---|
24 |
|
---|
25 | //get the image and the full path to the image
|
---|
26 | $image = rawurldecode($_GET['img']);
|
---|
27 | $fullpath = Files::makeFile($manager->getImagesDir(),$image);
|
---|
28 |
|
---|
29 | //not a file, so exit
|
---|
30 | if(!is_file($fullpath))
|
---|
31 | exit();
|
---|
32 |
|
---|
33 | $imgInfo = @getImageSize($fullpath);
|
---|
34 |
|
---|
35 | //Not an image, send default thumbnail
|
---|
36 | if(!is_array($imgInfo))
|
---|
37 | {
|
---|
38 | //show the default image, otherwise we quit!
|
---|
39 | $default = $manager->getDefaultThumb();
|
---|
40 | if($default)
|
---|
41 | {
|
---|
42 | header('Location: '.$default);
|
---|
43 | exit();
|
---|
44 | }
|
---|
45 | }
|
---|
46 | //if the image is less than the thumbnail dimensions
|
---|
47 | //send the original image as thumbnail
|
---|
48 | if ($imgInfo[0] <= $IMConfig['thumbnail_width']
|
---|
49 | && $imgInfo[1] <= $IMConfig['thumbnail_height'])
|
---|
50 | {
|
---|
51 | header('Location: '.$manager->getFileURL($image));
|
---|
52 | exit();
|
---|
53 | }
|
---|
54 |
|
---|
55 | //Check for thumbnails
|
---|
56 | $thumbnail = $manager->getThumbName($fullpath);
|
---|
57 | if(is_file($thumbnail))
|
---|
58 | {
|
---|
59 | //if the thumbnail is newer, send it
|
---|
60 | if(filemtime($thumbnail) >= filemtime($fullpath))
|
---|
61 | {
|
---|
62 | header('Location: '.$manager->getThumbURL($image));
|
---|
63 | exit();
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | //creating thumbnails
|
---|
68 | $thumbnailer = new Thumbnail($IMConfig['thumbnail_width'],$IMConfig['thumbnail_height']);
|
---|
69 | $thumbnailer->createThumbnail($fullpath, $thumbnail);
|
---|
70 |
|
---|
71 | //Check for NEW thumbnails
|
---|
72 | if(is_file($thumbnail))
|
---|
73 | {
|
---|
74 | //send the new thumbnail
|
---|
75 | header('Location: '.$manager->getThumbURL($image));
|
---|
76 | exit();
|
---|
77 | }
|
---|
78 | else
|
---|
79 | {
|
---|
80 | //show the default image, otherwise we quit!
|
---|
81 | $default = $manager->getDefaultThumb();
|
---|
82 | if($default)
|
---|
83 | header('Location: '.$default);
|
---|
84 | }
|
---|
85 | ?> |
---|