/opencore/js/thirdparty/xinha96r1270/plugins/ImageManager/resizer.php

https://github.com/socialplanning/oc-js · PHP · 88 lines · 55 code · 16 blank · 17 comment · 11 complexity · 9e227a25489e4610ad26a41a1801a41a MD5 · raw file

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