Пример #1
0
 function watermark($pic_path, $options = array())
 {
     $sys_config = jconf::get();
     if (!$sys_config['watermark_enable']) {
         return false;
     }
     if (!is_image($pic_path)) {
         return false;
     }
     $ims = @getimagesize($pic_path);
     if (in_array($ims['mime'], array('image/gif'))) {
         return false;
     }
     $new_pic_path = $options['new_pic_path'];
     if ('' == $new_pic_path) {
         $new_pic_path = $pic_path;
     }
     $image_quality = (int) $options['image_thumb_quality'];
     if ($image_quality < 1 || $image_quality > 100) {
         $image_quality = 100;
     }
     require_once ROOT_PATH . 'include/ext/thumb.class.php';
     $_thumb = new ThumbHandler();
     $_thumb->setSrcImg($pic_path);
     $_thumb->setDstImg($new_pic_path);
     $_thumb->setImgCreateQuality($image_quality);
     $_thumb->setMaskPosition($sys_config['watermark_position']);
     $_thumb->setMaskFontColor($sys_config['watermark_contents_color']);
     $_thumb->setMaskFontSize(max((int) $sys_config['watermark_contents_size'], 12));
     $watermark = $options['watermark'];
     if ('' == trim($watermark)) {
         $member_info = $options['member_info'];
         if (!$member_info) {
             $uid = (int) $options['uid'];
             $member_info = $uid > 0 ? jsg_member_info($uid) : array();
         }
         $username = $member_info['username'] ? $member_info['username'] : MEMBER_NAME;
         $nickname = $member_info['nickname'] ? $member_info['nickname'] : MEMBER_NICKNAME;
         if ($sys_config['watermark_contents'] && is_array($sys_config['watermark_contents'])) {
             if (in_array('nickname', $sys_config['watermark_contents']) && in_array('url', $sys_config['watermark_contents'])) {
                 $_thumb->setMaskOffsetY(40);
                 $_thumb->setMaskWord($sys_config['site_url'] . "/" . $username);
                 $_thumb->createImg(100);
                 $_thumb->setMaskOffsetY(10);
                 $options['watermark'] = '@' . $nickname;
                 return $this->watermark($pic_path, $options);
             } else {
                 if (in_array('nickname', $sys_config['watermark_contents'])) {
                     $watermark = '@' . $nickname;
                 } else {
                     $watermark = $sys_config['site_url'] . "/" . $username;
                 }
             }
         } else {
             $watermark = $sys_config['site_url'] . "/" . $username;
         }
     }
     if (is_file($watermark)) {
         $_thumb->setMaskImgPct(100);
         $_thumb->setMaskImg($watermark);
     } else {
         $mask_word = (string) $watermark;
         if ($sys_config['watermark_contents'] && in_array('nickname', $sys_config['watermark_contents']) && is_file(RELATIVE_ROOT_PATH . 'images/jsg.ttf')) {
             $_thumb->setMaskFont(RELATIVE_ROOT_PATH . 'images/jsg.ttf');
             $mask_word = array_iconv($sys_config['charset'], 'utf-8', $mask_word);
         } elseif (preg_match('~[\\x7f-\\xff][\\x7f-\\xff]~', $mask_word)) {
             $mask_word = $sys_config['site_url'];
         }
         $_thumb->setMaskWord($mask_word);
     }
     return $_thumb->createImg(100);
 }
Пример #2
0
         echo json_encode($_G['product']);
     }
     break;
     //////////////////////////////
     //水印预览
 //////////////////////////////
 //水印预览
 case "preview":
     require VI_ROOT . 'source/class/thumb.php';
     //关闭缓冲
     ob_end_clean();
     $t = new ThumbHandler();
     $t->setSrcImg(VI_ROOT . 'static/image/preview.jpg');
     if ($_G['setting']['attach']['MARK_OPEN'] == 'true') {
         $t->setMaskImg(VI_ROOT . $_G['setting']['attach']['MARK_FILE']);
         $t->setMaskPosition($_G['setting']['attach']['MARK_POSITION']);
     }
     $t->createImg(100);
     break;
     //////////////////////////////
     //授权方式
 //////////////////////////////
 //授权方式
 case "licence":
     //显示概要
     if ($execute == 'schema') {
         echo $_G['licence']['type'];
     } else {
         echo json_encode($_G['licence']);
     }
     break;
Пример #3
0
 public static function watermark()
 {
     //生成缩略
     if ($data['type'] == 'image' && $thumb) {
         //缩略图
         $t = new ThumbHandler();
         //源图片地址
         $t->setSrcImg($file);
         //输出文件名
         $t->setDstImg(str_replace("." . $data['extra'], "-thumb." . $data['extra'], $file));
         //给缩略_打上水印
         if ($_G['setting']["attach"]["MARK_OPEN"] == "true" && $param['water']['width'] && $param['water']['height'] && $thumb[0] / $param['water']['width'] > $param['multiple'] && $thumb[1] / $param['water']['height'] > $param['multiple']) {
             $t->setMaskImg($param['watermark']);
             $t->setMaskPosition($param['position']);
         }
         //生成图片
         $t->createImg($thumb[0], $thumb[1]);
     }
     //生成组图
     if ($data['type'] == 'image' && is_array($group)) {
         foreach ($group as $g) {
             $thumb = explode("*", $g);
             if (is_array($thumb)) {
                 //缩略图
                 $t = new ThumbHandler();
                 //源图片地址
                 $t->setSrcImg($file);
                 //输出文件名
                 $t->setDstImg(str_replace("." . $data['extra'], "-" . $thumb[0] . "-" . $thumb[1] . "." . $data['extra'], $file));
                 //给组图_打上水印
                 if ($_G['setting']["attach"]["MARK_OPEN"] == "true" && $param['water']['width'] && $param['water']['height'] && $thumb[0] / $param['water']['width'] > $param['multiple'] && $thumb[1] / $param['water']['height'] > $param['multiple']) {
                     $t->setMaskImg($param['watermark']);
                     $t->setMaskPosition($param['position']);
                 }
                 //生成图片
                 $t->createImg($thumb[0], $thumb[1]);
             }
         }
     }
     //给原图_打上水印
     if ($_G['setting']["attach"]["MARK_OPEN"] == "true" && $param['water']['width'] && $param['water']['height'] && $width / $param['water']['width'] > $param['multiple'] && $height / $param['water']['height'] > $param['multiple']) {
         //缩略图
         $t = new ThumbHandler();
         //源图片地址
         $t->setSrcImg($file);
         //输出文件名
         $t->setDstImg($file);
         $t->setMaskImg($param['watermark']);
         $t->setMaskPosition($param['position']);
         //生成图片
         $t->createImg($width, $height);
     }
 }