misc_imgcropper.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: misc_imgcropper.php 36314 2016-12-19 08:02:23Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $_GET['img'] = htmlspecialchars($_GET['img']);
  12. $_GET['bid'] = intval($_GET['bid']);
  13. $_GET['picflag'] = intval($_GET['picflag']);
  14. $_GET['ictype'] = !empty($_GET['ictype']) ? 'block' : '';
  15. $_GET['width'] = intval($_GET['width']);
  16. $_GET['height'] = intval($_GET['height']);
  17. if(!submitcheck('imgcroppersubmit')) {
  18. if($_GET['op'] == 'loadcropper') {
  19. $cboxwidth = $_GET['width'] > 50 ? $_GET['width'] : 300;
  20. $cboxheight = $_GET['height'] > 50 ? $_GET['height'] : 300;
  21. $cbgboxwidth = $cboxwidth + 300;
  22. $cbgboxheight = $cboxheight + 300;
  23. $dragpl = ($cbgboxwidth - $cboxwidth)/2;
  24. $dragpt = ($cbgboxheight - $cboxheight)/2;
  25. } else {
  26. $prefix = $_GET['picflag'] == 2 ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl'];
  27. }
  28. include_once template("common/misc_imgcropper");
  29. } else {
  30. $cropfile = md5($_GET['cutimg']).'.jpg';
  31. $ictype = $_GET['ictype'];
  32. if($ictype == 'block') {
  33. require_once libfile('function/block');
  34. $block = C::t('common_block')->fetch($_GET['bid']);
  35. $cropfile = block_thumbpath($block, array('picflag' => intval($_GET['picflag']), 'pic' => $_GET['cutimg']));
  36. $cutwidth = $block['picwidth'];
  37. $cutheight = $block['picheight'];
  38. } else {
  39. $cutwidth = $_GET['cutwidth'];
  40. $cutheight = $_GET['cutheight'];
  41. }
  42. $top = intval($_GET['cuttop'] < 0 ? 0 : $_GET['cuttop']);
  43. $left = intval($_GET['cutleft'] < 0 ? 0 : $_GET['cutleft']);
  44. $picwidth = $cutwidth > $_GET['picwidth'] ? $cutwidth : $_GET['picwidth'];
  45. $picheight = $cutheight > $_GET['picheight'] ? $cutheight : $_GET['picheight'];
  46. require_once libfile('class/image');
  47. $image = new image();
  48. $prefix = $_GET['picflag'] == 2 ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl'];
  49. if(!$image->Thumb($prefix.$_GET['cutimg'], $cropfile, $picwidth, $picheight)) {
  50. showmessage('imagepreview_errorcode_'.$image->errorcode, null, null, array('showdialog' => true, 'closetime' => true));
  51. }
  52. $image->Cropper($image->target, $cropfile, $cutwidth, $cutheight, $left, $top);
  53. showmessage('do_success', dreferer(), array('icurl' => $cropfile), array('showdialog' => true, 'closetime' => true));
  54. }
  55. ?>