Manage.php 2.4 KB

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