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

153 lines
5.0KB

  1. <?php
  2. if (!defined('DEDEINC')) exit ('dedebiz');
  3. require_once DEDEINC."/libraries/imageresize.class.php";
  4. /**
  5. * 图像处理函数
  6. *
  7. * @version $id:image.func.php 15:59 2010年7月5日 tianya $
  8. * @package DedeBIZ.Helpers
  9. * @copyright Copyright (c) 2022 DedeBIZ.COM
  10. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  11. * @link https://www.dedebiz.com
  12. */
  13. /**
  14. * 缩图片自动生成函数,来源支持bmp、gif、jpg、png但生成的小图只用jpg或png格式
  15. *
  16. * @access public
  17. * @param string $srcFile 图片路径
  18. * @param string $toW 转换到的宽度
  19. * @param string $toH 转换到的高度
  20. * @param string $toFile 输出文件到
  21. * @return string
  22. */
  23. if (!function_exists('ImageResize')) {
  24. function ImageResize($srcFile, $toW, $toH, $toFile = "")
  25. {
  26. try {
  27. $image = new ImageResize($srcFile);
  28. $image->resizeToBestFit($toW, $toH);
  29. $image->save($toFile);
  30. return true;
  31. } catch (ImageResizeException $e) {
  32. return false;
  33. }
  34. }
  35. }
  36. /**
  37. * 获得GD的版本
  38. *
  39. * @access public
  40. * @return int
  41. */
  42. if (!function_exists('gdversion')) {
  43. function gdversion()
  44. {
  45. //没启用php.ini函数的情况下如果有GD默认视作2.0以上版本
  46. if (!function_exists('phpinfo')) {
  47. if (function_exists('imagecreate')) {
  48. return '2.0';
  49. } else {
  50. return 0;
  51. }
  52. } else {
  53. ob_start();
  54. phpinfo(8);
  55. $module_info = ob_get_contents();
  56. ob_end_clean();
  57. if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info, $matches)) {
  58. $gdversion_h = $matches[1];
  59. } else {
  60. $gdversion_h = 0;
  61. }
  62. return $gdversion_h;
  63. }
  64. }
  65. }
  66. /**
  67. * 图片自动加水印函数
  68. *
  69. * @access public
  70. * @param string $srcFile 图片源文件
  71. * @param string $fromGo 位置
  72. * @return string
  73. */
  74. if (!function_exists('WaterImg')) {
  75. function WaterImg($srcFile, $fromGo = 'up')
  76. {
  77. include(DEDEDATA.'/mark/inc_photowatermark_config.php');
  78. require_once(DEDEINC.'/dedeimage.class.php');
  79. if (isset($GLOBALS['needwatermark'])) {
  80. $photo_markup = $photo_markdown = empty($GLOBALS['needwatermark']) ? '0' : '1';
  81. }
  82. if ($photo_markup != '1' || ($fromGo == 'collect' && $photo_markdown != '1')) {
  83. return;
  84. }
  85. $info = '';
  86. $srcInfo = @getimagesize($srcFile, $info);
  87. $srcFile_w = $srcInfo[0];
  88. $srcFile_h = $srcInfo[1];
  89. if ($srcFile_w < $photo_wwidth || $srcFile_h < $photo_wheight) {
  90. return;
  91. }
  92. if ($fromGo == 'up' && $photo_markup == '0') {
  93. return;
  94. }
  95. if ($fromGo == 'down' && $photo_markdown == '0') {
  96. return;
  97. }
  98. $TRUEMarkimg = DEDEDATA.'/mark/'.$photo_markimg;
  99. if (!file_exists($TRUEMarkimg) || empty($photo_markimg)) {
  100. $TRUEMarkimg = "";
  101. }
  102. if ($photo_waterpos == 0) {
  103. $photo_waterpos = rand(1, 9);
  104. }
  105. $cfg_watermarktext = array();
  106. if ($photo_marktype == '2') {
  107. if (file_exists(DEDEDATA.'/mark/simhei.ttf')) {
  108. $cfg_watermarktext['fontpath'] = DEDEDATA.'/mark/simhei.ttf';
  109. } else {
  110. return;
  111. }
  112. }
  113. $cfg_watermarktext['text'] = $photo_watertext;
  114. $cfg_watermarktext['size'] = $photo_fontsize;
  115. $cfg_watermarktext['angle'] = '0';
  116. $cfg_watermarktext['color'] = '255,255,255';
  117. $cfg_watermarktext['shadowx'] = '0';
  118. $cfg_watermarktext['shadowy'] = '0';
  119. $cfg_watermarktext['shadowcolor'] = '0,0,0';
  120. $photo_marktrans = 85;
  121. $img = new DedeImage($srcFile, 0, $cfg_watermarktext, $photo_waterpos, $photo_diaphaneity, $photo_wheight, $photo_wwidth, $photo_marktype, $photo_marktrans, $TRUEMarkimg);
  122. $img->watermark(0);
  123. }
  124. }
  125. /**
  126. * 会对空白地方填充满
  127. *
  128. * @access public
  129. * @param string $srcFile 图片路径
  130. * @param string $toW 转换到的宽度
  131. * @param string $toH 转换到的高度
  132. * @param string $toFile 输出文件到
  133. * @param string $issave 是否保存
  134. * @return bool
  135. */
  136. if (!function_exists('ImageResizeNew')) {
  137. function ImageResizeNew($srcFile, $toW, $toH, $toFile = '', $issave = TRUE)
  138. {
  139. try {
  140. $image = new ImageResize($srcFile);
  141. $image->resizeToBestFit($toW, $toH);
  142. if ($issave) {
  143. $image->save($toFile);
  144. } else {
  145. $image->output();
  146. }
  147. return true;
  148. } catch (ImageResizeException $e) {
  149. return false;
  150. }
  151. }
  152. }
  153. ?>