} else { 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']); }
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); }
fclose($fp); return true; } //下载图片 $filename = 'qqhead.jpg'; $url = $_POST['head']; getImg($url, $filename); if (file_exists('qqhead.jpg')) { //头像下载回来继续处理 $b = imagettfbbox(14, 0, "upload/fangzheng.ttf", $_POST['nickname']); //文字宽度 $w = abs($b[2] - $b[0]); $t = new ThumbHandler(); $t->setSrcImg("images/show.jpg"); $t->setDstImg("out.jpg"); $t->setMaskImg("qqhead.jpg"); $t->setMaskOffsetX(($t->src_w + $w) / 2 + 20); $t->setMaskOffsetY($t->src_h - 150); $t->setMaskImgPct(100); $t->createImg(100); // 指定缩放比例 // 第二个水印 名字 $t2 = new ThumbHandler(); $t2->setSrcImg(dirname(__FILE__) . '/' . 'out.jpg'); $t2->setMaskFont("upload/fangzheng.ttf"); $t2->setMaskFontSize(16); $t2->setMaskFontColor("#1A6BE6"); $t2->setMaskTxtPct(20); $t2->setDstImg(dirname(__FILE__) . '/' . 'out.jpg'); $t2->setMaskOffsetX(($t->src_w - $w) / 2); $t2->setMaskOffsetY($t2->src_h + $t2->font_h - 150);
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); } }