1 | <?php
|
---|
2 | header('Content-Type: text/javascript; charset=UTF-8');
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * Resize images to a given size, and saving in a new file.
|
---|
6 | * resize.php?img=/relative/path/to/image.jpg&width=<pixels>&height=<pixels>[&to=/relative/path/to/newimage.jpg]
|
---|
7 | * relative to the base_dir given in config.inc.php
|
---|
8 | * This is pretty much just thumbs.php with some mods, I'm too lazy to do it properly
|
---|
9 | * @author $Author:ray $
|
---|
10 | * @version $Id:resizer.php 922 2007-12-30 14:35:46Z ray $
|
---|
11 | * @package ImageManager
|
---|
12 | */
|
---|
13 |
|
---|
14 | require_once('config.inc.php');
|
---|
15 | require_once('Classes/ExtendedFileManager.php');
|
---|
16 | require_once('../ImageManager/Classes/Thumbnail.php');
|
---|
17 |
|
---|
18 | function js_fail($message) { echo 'alert(\'ha ' . $message . '\'); false'; exit; }
|
---|
19 | function js_success($resultFile) { echo '\'' . $resultFile . '\''; exit; }
|
---|
20 |
|
---|
21 | //check for img parameter in the url
|
---|
22 | if(!isset($_GET['img']) || !isset($_GET['width']) || !isset($_GET['height']))
|
---|
23 | {
|
---|
24 | js_fail('Missing parameter.');
|
---|
25 | }
|
---|
26 |
|
---|
27 | if($IMConfig['resize_files'] == FALSE)
|
---|
28 | {
|
---|
29 | js_success($_GET['img']);
|
---|
30 | }
|
---|
31 |
|
---|
32 | $manager = new ExtendedFileManager($IMConfig);
|
---|
33 |
|
---|
34 | //get the image and the full path to the image
|
---|
35 | $image = $_GET['img'];
|
---|
36 | $fullpath = Files::makeFile($manager->getImagesDir(),$image);
|
---|
37 |
|
---|
38 | //not a file, so exit
|
---|
39 | if(!is_file($fullpath))
|
---|
40 | {
|
---|
41 | js_fail("File {$fullpath} does not exist.");
|
---|
42 | }
|
---|
43 |
|
---|
44 | $imgInfo = @getImageSize($fullpath);
|
---|
45 |
|
---|
46 | //Not an image, bail out.
|
---|
47 | if(!is_array($imgInfo))
|
---|
48 | {
|
---|
49 | js_fail("File {$fullpath} is not an image.");
|
---|
50 | }
|
---|
51 |
|
---|
52 | if(!isset($_GET['to']))
|
---|
53 | {
|
---|
54 | $resized = $manager->getResizedName($fullpath,$_GET['width'],$_GET['height']);
|
---|
55 | $_GET['to'] = $manager->getResizedName($image,$_GET['width'],$_GET['height'], FALSE);
|
---|
56 | }
|
---|
57 | else
|
---|
58 | {
|
---|
59 | $resized = Files::makeFile($manager->getImagesDir(),$_GET['to']);
|
---|
60 | }
|
---|
61 |
|
---|
62 | // Check to see if it already exists
|
---|
63 | if(is_file($resized))
|
---|
64 | {
|
---|
65 | // And is newer
|
---|
66 | if(filemtime($resized) >= filemtime($fullpath))
|
---|
67 | {
|
---|
68 | js_success($_GET['to']);
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 | // resize (thumbnailer will do this for us just fine)
|
---|
75 | $thumbnailer = new Thumbnail($_GET['width'],$_GET['height']);
|
---|
76 | $thumbnailer->proportional = FALSE;
|
---|
77 | $thumbnailer->createThumbnail($fullpath, $resized);
|
---|
78 |
|
---|
79 | // did it work?
|
---|
80 | if(is_file($resized))
|
---|
81 | {
|
---|
82 | js_success($_GET['to']);
|
---|
83 | }
|
---|
84 | else
|
---|
85 | {
|
---|
86 | js_fail("Resize Failed.");
|
---|
87 | }
|
---|
88 | ?> |
---|