Manage.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php namespace Image\Api;
  2. use Dever;
  3. use Manage\Lib\Auth;
  4. class Manage extends Auth
  5. {
  6. public function set()
  7. {
  8. $data = array();
  9. $data['id'] = Dever::input('id');
  10. $data['state'] = Dever::input('state');
  11. $data['pic'] = Dever::input('pic');
  12. $data['wh'] = Dever::input('wh');
  13. $data['ratio'] = 16 / 9;
  14. if ($data['wh']) {
  15. if (strstr($data['wh'], '*')) {
  16. $data['ratio'] = $this->ratio('*', $data['wh']);
  17. } elseif (strstr($data['wh'], 'x')) {
  18. $data['ratio'] = $this->ratio('x', $data['wh']);
  19. } elseif (strstr($data['wh'], 'X')) {
  20. $data['ratio'] = $this->ratio('X', $data['wh']);
  21. } else {
  22. $data['ratio'] = 1;
  23. }
  24. }
  25. $data['search_cate'] = 1;
  26. $data['param'] = '';
  27. if (strstr($data['pic'], '_cr_')) {
  28. $ext = '.' . pathinfo($data['pic'], PATHINFO_EXTENSION);
  29. $temp = explode('_cr_', $data['pic']);
  30. $param = $data['pic'];
  31. $data['pic'] = $temp[0];
  32. $data['param'] = str_replace($ext, '', $temp[1]);
  33. }
  34. $data['submit'] = Dever::url('image/manage.cropper');
  35. Dever::view('set', $data);
  36. }
  37. public function cropper()
  38. {
  39. $send['param'] = array();
  40. $input = Dever::input();
  41. foreach ($input as $k => $v) {
  42. if (strpos($k, 'param_') === 0) {
  43. $send['param'][$k] = $v;
  44. }
  45. }
  46. $cate = 2;
  47. $id = Dever::input('id');
  48. $source = Dever::input('img');
  49. $dest = Dever::input('pic');
  50. $dest = explode('/', $dest);
  51. $dest = end($dest);
  52. $dest .= '_cr_' . implode('_', $send['param']);
  53. $result = Dever::load('save', 'upload')->act($id, $source, false, false, $dest, $cate);
  54. return $result;
  55. }
  56. private function ratio($str, $wh)
  57. {
  58. $temp = explode($str, $wh);
  59. $ratio = $temp[0] / $temp[1];
  60. return $ratio;
  61. }
  62. }