国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.5KB

  1. <?php
  2. /**
  3. * 截取图片
  4. *
  5. * @version $Id: imagecut.php 1 11:06 2010年7月13日Z tianya $
  6. * @package DedeCMS.Administrator
  7. * @copyright Copyright (c) 2007 - 2018, DesDev, Inc.
  8. * @copyright Copyright (c) 2020, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license/v6
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(dirname(__FILE__).'/config.php');
  13. $action = isset($action) ? trim($action) : '';
  14. if(empty($action))
  15. {
  16. if(!@is_file($cfg_basedir.$file))
  17. {
  18. ShowMsg("对不起,必须选择站内的图片才能进行裁剪!<br />点击'<a href='./dialog/select_images.php?f=form1.picname&imgstick=small'>站内选择</a>', 上传或选择一个图片,然后才能进行裁剪!", "./dialog/select_images.php?f=form1.picname&imgstick=small", 0 , 10000);
  19. exit();
  20. }
  21. include DEDEADMIN.'/templets/imagecut.htm';
  22. exit();
  23. }
  24. elseif($action == 'cut')
  25. {
  26. require_once(DEDEINC.'/image.func.php');
  27. if(!@is_file($cfg_basedir.$file))
  28. {
  29. ShowMsg('对不起,请重新选择裁剪图片!', '-1');
  30. exit();
  31. }
  32. if(empty($width))
  33. {
  34. ShowMsg('对不起,请选择裁剪图片的尺寸!', '-1');
  35. exit();
  36. }
  37. if(empty($height))
  38. {
  39. ShowMsg('对不起,请选择裁剪图片的尺寸!', '-1');
  40. exit();
  41. }
  42. $imginfo = getimagesize($cfg_basedir.$file);
  43. $imgw = $imginfo[0];
  44. $imgh = $imginfo[1];
  45. $temp = 400/$imgw;
  46. $newwidth = 400;
  47. $newheight = $imgh * $temp;
  48. $srcFile = $cfg_basedir.$file;
  49. $thumb = imagecreatetruecolor($newwidth, $newheight);
  50. $thumba = imagecreatetruecolor($width, $height);
  51. switch($imginfo['mime'])
  52. {
  53. case 'image/jpeg':
  54. $source = imagecreatefromjpeg($srcFile);
  55. break;
  56. case 'image/gif':
  57. $source = imagecreatefromgif($srcFile);
  58. break;
  59. case 'image/png':
  60. $source = imagecreatefrompng($srcFile);
  61. break;
  62. default:
  63. ShowMsg('对不起,裁剪图片类型不支持请选择其他类型图片!', '-1');
  64. break;
  65. }
  66. imagecopyresized($thumb, $source, 0, 0, 0, 0 , $newwidth, $newheight, $imgw, $imgh);
  67. imagecopy($thumba, $thumb, 0, 0, $left, $top, $newwidth, $newheight);
  68. $ddn = substr($srcFile, -3);
  69. $ddpicok = $reObjJs = '';
  70. if( empty($isupload) )
  71. {
  72. $ddpicok = preg_replace("#\.".$ddn."$#", '-lp.'.$ddn, $file);
  73. $reObjJs = " var backObj = window.opener.document.form1.picname;
  74. var prvObj = window.opener.document.getElementById('divpicview');\r\n";
  75. }
  76. else
  77. {
  78. $ddpicok = $file;
  79. $reObjJs = " var backObj = window.opener.parent.document.form1.picname;
  80. var prvObj = window.opener.parent.document.getElementById('divpicview');\r\n";
  81. }
  82. $ddpicokurl = $cfg_basedir.$ddpicok;
  83. switch($imginfo['mime'])
  84. {
  85. case 'image/jpeg':
  86. imagejpeg($thumba, $ddpicokurl, 85);
  87. break;
  88. case 'image/gif':
  89. imagegif($thumba, $ddpicokurl);
  90. break;
  91. case 'image/png':
  92. imagepng($thumba, $ddpicokurl);
  93. break;
  94. default:
  95. ShowMsg("对不起,裁剪图片类型不支持请选择其他类型图片!", "-1");
  96. break;
  97. }
  98. //对任意裁剪方式再次缩小图片至限定大小
  99. if($newwidth > $cfg_ddimg_width || $newheight > $cfg_ddimg_height)
  100. {
  101. ImageResize($ddpicokurl, $cfg_ddimg_width, $cfg_ddimg_height);
  102. }
  103. //如果从其它图中剪出, 保存附件信息
  104. if( empty($isupload) )
  105. {
  106. $inquery = "INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  107. VALUES ('$ddpicok','$ddpicok','1','0','0','0','".filesize($ddpicokurl)."','".time()."','".$cuserLogin->getUserID()."'); ";
  108. $dsql->ExecuteNoneQuery($inquery);
  109. $fid = $dsql->GetLastID();
  110. AddMyAddon($fid, $ddpicok);
  111. }
  112. ?>
  113. <SCRIPT language=JavaScript>
  114. function ReturnImg(reimg)
  115. {
  116. <?php echo $reObjJs; ?>
  117. backObj.value = reimg;
  118. if(prvObj)
  119. {
  120. prvObj.style.width = '150px';
  121. prvObj.innerHTML = "<img src='"+reimg+"?n' width='150' />";
  122. }
  123. if(document.all) {
  124. window.opener=true;
  125. }
  126. window.close();
  127. }
  128. ReturnImg("<?php echo $ddpicok; ?>");
  129. </SCRIPT>
  130. <?php
  131. }
  132. ?>