source: trunk/plugins/ImageManager/resizer.php @ 1081

Last change on this file since 1081 was 999, checked in by ray, 11 years ago

#1195 Allow to specify an external url to load a plugin from

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 2.0 KB
Line 
1<?php
2header('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
14require_once('config.inc.php');
15require_once('Classes/ImageManager.php');
16require_once('Classes/Thumbnail.php');
17
18function js_fail($message)    { echo 'alert(\'' . $message . '\'); false'; exit;   }
19function js_success($resultFile)    { echo '\'' . $resultFile . '\''; exit;   }
20
21//check for img parameter in the url
22if(!isset($_GET['img']) || !isset($_GET['width']) || !isset($_GET['height']))
23{
24  js_fail('Missing parameter.');
25}
26
27$manager = new ImageManager($IMConfig);
28
29//get the image and the full path to the image
30$image = $_GET['img'];
31$fullpath = Files::makeFile($manager->getImagesDir(),$image);
32
33//not a file, so exit
34if(!is_file($fullpath))
35{
36  js_fail("File {$fullpath} does not exist.");
37}
38
39$imgInfo = @getImageSize($fullpath);
40
41//Not an image, bail out.
42if(!is_array($imgInfo))
43{
44        js_fail("File {$fullpath} is not an image.");
45}
46
47if(!isset($_GET['to']))
48{
49  $resized    = $manager->getResizedName($fullpath,$_GET['width'],$_GET['height']);
50  $_GET['to'] = $manager->getResizedName($image,$_GET['width'],$_GET['height'], FALSE);
51}
52else
53{
54  $resized = Files::makeFile($manager->getImagesDir(),$_GET['to']);
55}
56
57// Check to see if it already exists
58if(is_file($resized))
59{
60        // And is newer
61        if(filemtime($resized) >= filemtime($fullpath))
62        {
63                js_success($_GET['to']);
64        }
65}
66
67
68
69// resize (thumbnailer will do this for us just fine)
70$thumbnailer = new Thumbnail($_GET['width'],$_GET['height']);
71$thumbnailer->proportional = FALSE;
72$thumbnailer->createThumbnail($fullpath, $resized);
73
74// did it work?
75if(is_file($resized))
76{
77        js_success($_GET['to']);
78}
79else
80{
81        js_fail("Resize Failed.");
82}
83?>
Note: See TracBrowser for help on using the repository browser.