Manage.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php namespace Image\Manage\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['project'] = Dever::input('project');
  21. $data['ratio'] = 16 / 9;
  22. if ($data['wh']) {
  23. if (strstr($data['wh'], '*')) {
  24. $data['ratio'] = $this->ratio('*', $data['wh']);
  25. } elseif (strstr($data['wh'], 'x')) {
  26. $data['ratio'] = $this->ratio('x', $data['wh']);
  27. } elseif (strstr($data['wh'], 'X')) {
  28. $data['ratio'] = $this->ratio('X', $data['wh']);
  29. } else {
  30. $data['ratio'] = 1;
  31. }
  32. }
  33. $data['search_cate'] = 1;
  34. $data['param'] = '';
  35. if (strstr($data['pic'], '?')) {
  36. $temp = explode('?', $data['pic']);
  37. $data['pic'] = $temp[0];
  38. }
  39. if (strstr($data['pic'], '_cr_')) {
  40. $ext = '.' . pathinfo($data['pic'], PATHINFO_EXTENSION);
  41. $temp = explode('_cr_', $data['pic']);
  42. $param = $data['pic'];
  43. $data['pic'] = $temp[0];
  44. $data['param'] = str_replace($ext, '', $temp[1]);
  45. }
  46. # 查找原图
  47. $data['pic'] = Dever::load(\Upload\Lib\View::class)->getSource($data['pic'], true);
  48. $data['submit'] = Dever::url('image/manage.cropper');
  49. Dever::view('set', $data);
  50. }
  51. public function cropper()
  52. {
  53. $send['param'] = array();
  54. $input = Dever::input();
  55. foreach ($input as $k => $v) {
  56. if (strpos($k, 'param_') === 0) {
  57. $send['param'][$k] = $v;
  58. }
  59. }
  60. $cate = 3;
  61. $group_id = Dever::input('group_id');
  62. $user_id = Dever::input('user_id');
  63. $project = Dever::input('project');
  64. $id = Dever::input('id');
  65. $source = Dever::input('img');
  66. $dest = Dever::input('pic');
  67. $dest = explode('/upload/', $dest);
  68. $dest = end($dest);
  69. $dest .= '_cr_' . implode('_', $send['param']) . '.png';
  70. $result = Dever::load(Save::class)->init($id, $cate, $group_id, $user_id, $project)->act($source, false, false, $dest);
  71. return $result;
  72. }
  73. private function ratio($str, $wh)
  74. {
  75. $temp = explode($str, $wh);
  76. $ratio = $temp[0] / $temp[1];
  77. return $ratio;
  78. }
  79. }