dz底部黑条水印 仿铁血黑条水印 无错修正版 for 适用于dz!x系列所有版本

[复制链接]
查看2137 | 回复0 | 2020-2-18 13:23 | 显示全部楼层 |阅读模式
discuz底部黑条水印 仿铁血黑条水印 无错修正版 for 适用于dz!x系列所有版本
效果如图所示:

dz底部黑条水印 仿铁血黑条水印 无错修正版 for 适用于dz!x系列所有版本

dz底部黑条水印 仿铁血黑条水印 无错修正版 for 适用于dz!x系列所有版本


文件 /source/class/class_image.php 记得要有中文字体才能出现汉字 static/image/seccode/font/ch/   加入汉字字体后台设置好,建议使用 免费商用字体
  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: class_image.php 36349 2017-01-16 03:05:23Z nemohou $
  7. */

  8. if(!defined('IN_DISCUZ')) {
  9.         exit('Access Denied');
  10. }

  11. class image {

  12.         var $source = '';
  13.         var $target = '';
  14.         var $imginfo = array();
  15.         var $imagecreatefromfunc = '';
  16.         var $imagefunc = '';
  17.         var $tmpfile = '';
  18.         var $libmethod = 0;
  19.         var $param = array();
  20.         var $errorcode = 0;

  21.         var $extension = array();

  22.         function __construct() {
  23.                 global $_G;


  24.                 $this->extension['gd'] = extension_loaded('gd');
  25.                 $this->extension['imagick'] = extension_loaded('imagick');

  26.                 $this->param = array(
  27.                                 'imagelib'                => $_G['setting']['imagelib'],
  28.                                 'imageimpath'                => $_G['setting']['imageimpath'],
  29.                                 'thumbquality'                => $_G['setting']['thumbquality'],
  30.                                 'watermarkstatus'        => dunserialize($_G['setting']['watermarkstatus']),
  31.                                 'watermarkminwidth'        => dunserialize($_G['setting']['watermarkminwidth']),
  32.                                 'watermarkminheight'        => dunserialize($_G['setting']['watermarkminheight']),
  33.                                 'watermarktype'                => $_G['setting']['watermarktype'],
  34.                                 'watermarktext'                => $_G['setting']['watermarktext'],
  35.                                 'watermarktrans'        => dunserialize($_G['setting']['watermarktrans']),
  36.                                 'watermarkquality'        => dunserialize($_G['setting']['watermarkquality']),
  37.                 );
  38.         }


  39.         function Thumb($source, $target, $thumbwidth, $thumbheight, $thumbtype = 1, $nosuffix = 0) {
  40.                 $return = $this->init('thumb', $source, $target, $nosuffix);
  41.                 if($return <= 0) {
  42.                         return $this->returncode($return);
  43.                 }

  44.                 if($this->imginfo['animated']) {
  45.                         return $this->returncode(0);
  46.                 }
  47.                 $this->param['thumbwidth'] = intval($thumbwidth);
  48.                 if(!$thumbheight || $thumbheight > $this->imginfo['height']) {
  49.                         $thumbheight = $thumbwidth > $this->imginfo['width'] ? $this->imginfo['height'] : $this->imginfo['height']*($thumbwidth/$this->imginfo['width']);
  50.                 }
  51.                 $this->param['thumbheight'] = intval($thumbheight);
  52.                 $this->param['thumbtype'] = $thumbtype;
  53.                 if($thumbwidth < 100 && $thumbheight < 100) {
  54.                         $this->param['thumbquality'] = 100;
  55.                 }

  56.                 $return = !$this->libmethod ? $this->Thumb_GD() : $this->Thumb_IM();
  57.                 $return = !$nosuffix ? $return : 0;

  58.                 return $this->sleep($return);
  59.         }

  60.         function Cropper($source, $target, $dstwidth, $dstheight, $srcx = 0, $srcy = 0, $srcwidth = 0, $srcheight = 0) {

  61.                 $return = $this->init('thumb', $source, $target, 1);
  62.                 if($return <= 0) {
  63.                         return $this->returncode($return);
  64.                 }
  65.                 if($dstwidth < 0 || $dstheight < 0) {
  66.                         return $this->returncode(false);
  67.                 }
  68.                 $this->param['dstwidth'] = intval($dstwidth);
  69.                 $this->param['dstheight'] = intval($dstheight);
  70.                 $this->param['srcx'] = intval($srcx);
  71.                 $this->param['srcy'] = intval($srcy);
  72.                 $this->param['srcwidth'] = intval($srcwidth ? $srcwidth : $dstwidth);
  73.                 $this->param['srcheight'] = intval($srcheight ? $srcheight : $dstheight);

  74.                 $return = !$this->libmethod ? $this->Cropper_GD() : $this->Cropper_IM();
  75.         }

  76.         function Watermark($source, $target = '', $type = 'forum') {
  77.                 $return = $this->init('watermask', $source, $target);
  78.                 if($return <= 0) {
  79.                         return $this->returncode($return);
  80.                 }

  81.                 if(!$this->param['watermarkstatus'][$type] || ($this->param['watermarkminwidth'][$type] && $this->imginfo['width'] <= $this->param['watermarkminwidth'][$type] && $this->param['watermarkminheight'][$type] && $this->imginfo['height'] <= $this->param['watermarkminheight'][$type])) {
  82.                         return $this->returncode(0);
  83.                 }
  84.                 $this->param['watermarkfile'][$type] = './static/image/common/'.($this->param['watermarktype'][$type] == 'png' ? 'watermark.png' : 'watermark.gif');
  85.                 if(!is_readable($this->param['watermarkfile'][$type]) || ($this->param['watermarktype'][$type] == 'text' && (!file_exists($this->param['watermarktext']['fontpath'][$type]) || !is_file($this->param['watermarktext']['fontpath'][$type])))) {
  86.                         return $this->returncode(-3);
  87.                 }

  88.                 $return = !$this->libmethod ? $this->Watermark_GD($type) : $this->Watermark_IM($type);

  89.                 return $this->sleep($return);
  90.         }

  91.         function error() {
  92.                 return $this->errorcode;
  93.         }

  94.         function init($method, $source, $target, $nosuffix = 0) {
  95.                 global $_G;

  96.                 $this->errorcode = 0;
  97.                 if(empty($source)) {
  98.                         return -2;
  99.                 }
  100.                 $parse = parse_url($source);
  101.                 if(isset($parse['host'])) {
  102.                         if(empty($target)) {
  103.                                 return -2;
  104.                         }
  105.                         $data = dfsockopen($source);
  106.                         $this->tmpfile = $source = tempnam($_G['setting']['attachdir'].'./temp/', 'tmpimg_');
  107.                         if(!$data || $source === FALSE) {
  108.                                 return -2;
  109.                         }
  110.                         file_put_contents($source, $data);
  111.                 }
  112.                 if($method == 'thumb') {
  113.                         $target = empty($target) ? (!$nosuffix ? getimgthumbname($source) : $source) : $_G['setting']['attachdir'].'./'.$target;
  114.                 } elseif($method == 'watermask') {
  115.                         $target = empty($target) ?  $source : $_G['setting']['attachdir'].'./'.$target;
  116.                 }
  117.                 $targetpath = dirname($target);
  118.                 dmkdir($targetpath);

  119.                 clearstatcache();
  120.                 if(!is_readable($source) || !is_writable($targetpath)) {
  121.                         return -2;
  122.                 }

  123.                 $imginfo = @getimagesize($source);
  124.                 if($imginfo === FALSE) {
  125.                         return -1;
  126.                 }

  127.                 $this->source = $source;
  128.                 $this->target = $target;
  129.                 $this->imginfo['width'] = $imginfo[0];
  130.                 $this->imginfo['height'] = $imginfo[1];
  131.                 $this->imginfo['mime'] = $imginfo['mime'];
  132.                 $this->imginfo['size'] = @filesize($source);
  133.                 $this->libmethod = $this->param['imagelib'];
  134.                 if(!$this->param['imagelib'] && $this->extension['gd']) {
  135.                         $this->libmethod = 0;
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-4-26