cut.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * 裁剪
  4. *********************************/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class cutControl extends BaseCircleControl {
  7. public function __construct(){
  8. Language::read('cut');
  9. parent::__construct();
  10. }
  11. /**
  12. * 图片上传
  13. *
  14. */
  15. public function pic_uploadOp(){
  16. if (chksubmit()){
  17. //上传图片
  18. $upload = new UploadFile();
  19. $upload->set('thumb_width', 500);
  20. $upload->set('thumb_height',499);
  21. $upload->set('thumb_ext','_small');
  22. $upload->set('max_size',C('image_max_filesize')?C('image_max_filesize'):1024);
  23. $upload->set('ifremove',true);
  24. $upload->set('default_dir',$_GET['uploadpath']);
  25. if (!empty($_FILES['c_img']['tmp_name'])){
  26. $result = $upload->upfile('c_img');
  27. if ($result){
  28. exit(json_encode(array('status'=>1,'url'=>UPLOAD_SITE_URL.'/'.$_GET['uploadpath'].'/'.$upload->thumb_image)));
  29. }else {
  30. exit(json_encode(array('status'=>0,'msg'=>$upload->error)));
  31. }
  32. }
  33. }
  34. }
  35. /**
  36. * 图片裁剪
  37. *
  38. */
  39. public function pic_cutOp(){
  40. import('function.thumb');
  41. if (chksubmit()){
  42. $thumb_width = $_POST['x'];
  43. $x1 = $_POST["x1"];
  44. $y1 = $_POST["y1"];
  45. $x2 = $_POST["x2"];
  46. $y2 = $_POST["y2"];
  47. $w = $_POST["w"];
  48. $h = $_POST["h"];
  49. $scale = $thumb_width/$w;
  50. $src = str_ireplace(UPLOAD_SITE_URL,BASE_UPLOAD_PATH,$_POST['url']);
  51. if (strpos($src, '..') !== false || strpos($src, BASE_UPLOAD_PATH) !== 0) {
  52. exit();
  53. }
  54. if (!empty($_POST['filename'])){
  55. $save_file2 = BASE_UPLOAD_PATH.'/'.$_POST['filename'];
  56. }else{
  57. $save_file2 = str_replace('_small.','_sm.',$src);
  58. }
  59. $cropped = resize_thumb($save_file2, $src,$w,$h,$x1,$y1,$scale);
  60. @unlink($src);
  61. $pathinfo = pathinfo($save_file2);
  62. exit($pathinfo['basename']);
  63. }
  64. $save_file = str_ireplace(UPLOAD_SITE_URL,BASE_UPLOAD_PATH,$_GET['url']);
  65. $_GET['x'] = (intval($_GET['x'])>50 && $_GET['x']<400) ? $_GET['x'] : 200;
  66. $_GET['y'] = (intval($_GET['y'])>50 && $_GET['y']<400) ? $_GET['y'] : 200;
  67. $_GET['resize'] = $_GET['resize'] == '0' ? '0' : '1';
  68. Tpl::output('height',get_height($save_file));
  69. Tpl::output('width',get_width($save_file));
  70. Tpl::showpage('cut','null_layout');
  71. }
  72. // public function pic_viewOp(){
  73. // header('Cache-Control:no-cache,must-revalidate');
  74. // header('Pragma:no-cache');
  75. // header('Content-type: image/jpeg');
  76. // echo file_get_contents($_GET['url']);
  77. // }
  78. }