PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/adminstrator/ajaxfilemanager/ajax_editor_reset.php

http://marocmall.googlecode.com/
PHP | 118 lines | 101 code | 8 blank | 9 comment | 12 complexity | e928a8257560f653149c1bfbba369386 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * reset the image
  4. * @author Logan Cai (cailongqun [at] yahoo [dot] com [dot] cn)
  5. * @link www.phpletter.com
  6. * @since 22/May/2007
  7. *
  8. */
  9. require_once('../../config/config.inc.php');
  10. require_once('../init.php');
  11. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "config.php");
  12. if (!isset($_POST['path']))
  13. {
  14. $_POST['path'] = "uploaded/Winter.jpg" . "?" . makeQueryString(array('path'));
  15. //for crop
  16. $_POST['mode'] = "crop";
  17. $_POST['x'] = 100;
  18. $_POST['y'] = 100;
  19. $imageInfo = @GetImageSize($_POST['path']);
  20. $_POST['width'] = $imageInfo[0];
  21. $_POST['height'] = $imageInfo[1];
  22. }
  23. initSessionHistory($_POST['path']);
  24. echo "{";
  25. $error = "";
  26. $info = "";
  27. if (empty($_POST['path']))
  28. {
  29. $error = IMG_SAVE_EMPTY_PATH;
  30. }elseif (!file_exists($_POST['path']))
  31. {
  32. $error = IMG_SAVE_NOT_EXISTS;
  33. }elseif (!isUnderRoot($_POST['path']))
  34. {
  35. $error = IMG_SAVE_PATH_DISALLOWED;
  36. }
  37. else
  38. {
  39. if (!empty($_POST['mode']))
  40. {
  41. include_once(CLASS_IMAGE);
  42. $image = new Image();
  43. $image->loadImage($_POST['path']);
  44. switch($_POST['mode'])
  45. {
  46. case "resize":
  47. if (!$image->resize($_POST['width'], $_POST['height'], (!empty($_POST['constraint'])?true:false)))
  48. {
  49. $error = IMG_SAVE_RESIZE_FAILED;
  50. }
  51. break;
  52. case "crop":
  53. if (!$image->cropToDimensions($_POST['x'], $_POST['y'], (int)($_POST['x']) + (int)($_POST['width']), (int)($_POST['y']) + (int)($_POST['height'])))
  54. {
  55. $error = IMG_SAVE_CROP_FAILED;
  56. }
  57. break;
  58. case "flip":
  59. if (!$image->flip($_POST['flip_angle']))
  60. {
  61. $error = IMG_SAVE_FLIP_FAILED;
  62. }
  63. break;
  64. case "rotate":
  65. if (!$image->rotate((int)($_POST['angle'])))
  66. {
  67. $error = IMG_SAVE_ROTATE_FAILED;
  68. }
  69. break;
  70. default:
  71. $error = IMG_SAVE_UNKNOWN_MODE;
  72. }
  73. if (empty($error))
  74. {
  75. $sessionNewPath = $session->getSessionDir() . uniqid(md5(time())) . "." . getFileExt($_POST['path']);
  76. if (!@copy($_POST['path'], $sessionNewPath))
  77. {
  78. $error = IMG_SAVE_BACKUP_FAILED;
  79. }else
  80. {
  81. addSessionHistory($_POST['path'], $sessionNewPath);
  82. if ($image->saveImage($_POST['path']))
  83. {
  84. $imageInfo = $image->getFinalImageInfo();
  85. $info .= ",width:" . $imageInfo['width'] . "\n";
  86. $info .= ",height:" . $imageInfo['height'] . "\n";
  87. $info .= ",size:'" . transformFileSize($imageInfo['size']) . "'\n";
  88. }else
  89. {
  90. $error = IMG_SAVE_FAILED;
  91. }
  92. }
  93. }else
  94. {
  95. //$image->DestroyImages();
  96. }
  97. }else
  98. {
  99. $error = IMG_SAVE_UNKNOWN_MODE;
  100. }
  101. }
  102. echo "error:'" . $error . "'\n";
  103. if (isset($image) && is_object($image))
  104. {
  105. $image->DestroyImages();
  106. }
  107. echo $info;
  108. echo ",history:" . sizeof($_SESSION[$_POST['path']]) . "\n";
  109. echo "}";
  110. ?>