国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

141 satır
4.4KB

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