Manage.php 2.6 KB

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