| 1 | <?php |
|---|
| 2 | header('Content-Type: text/javascript; charset=UTF-8'); |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 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 | |
|---|
| 22 | if(!isset($_GET['img']) || !isset($_GET['width']) || !isset($_GET['height'])) |
|---|
| 23 | { |
|---|
| 24 | js_fail('Missing parameter.'); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | $manager = new ExtendedFileManager($IMConfig); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | $image = $_GET['img']; |
|---|
| 31 | $fullpath = Files::makeFile($manager->getImagesDir(),$image); |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | if(!is_file($fullpath)) |
|---|
| 35 | { |
|---|
| 36 | js_fail("File {$fullpath} does not exist."); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | $imgInfo = @getImageSize($fullpath); |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | if(!is_array($imgInfo)) |
|---|
| 43 | { |
|---|
| 44 | js_fail("File {$fullpath} is not an image."); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | if(!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 | } |
|---|
| 52 | else |
|---|
| 53 | { |
|---|
| 54 | $resized = Files::makeFile($manager->getImagesDir(),$_GET['to']); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | if(is_file($resized)) |
|---|
| 59 | { |
|---|
| 60 | |
|---|
| 61 | if(filemtime($resized) >= filemtime($fullpath)) |
|---|
| 62 | { |
|---|
| 63 | js_success($_GET['to']); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | $thumbnailer = new Thumbnail($_GET['width'],$_GET['height']); |
|---|
| 71 | $thumbnailer->proportional = FALSE; |
|---|
| 72 | $thumbnailer->createThumbnail($fullpath, $resized); |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | if(is_file($resized)) |
|---|
| 76 | { |
|---|
| 77 | js_success($_GET['to']); |
|---|
| 78 | } |
|---|
| 79 | else |
|---|
| 80 | { |
|---|
| 81 | js_fail("Resize Failed."); |
|---|
| 82 | } |
|---|
| 83 | ?> |
|---|