Manage.php 2.3 KB

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