国内流行的内容管理系统(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.

imagecut.php 4.5KB

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