Manage.php 2.4 KB

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