Manage.php 2.6 KB

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