<?php 
class cls_ctl_pic extends cls_pic
{
	private $config=array();
	function __construct()
	{
		self::init_config();
	}
	//生成缩图
	function on_resize($msg_path,$msg_new_path="",$msg_w=0,$msg_h=0)
	{
		if(!isset($this->config["allow_resize"])||$this->config["allow_resize"]!=1) return "系统未开通缩略图功能！";
		if($msg_new_path=="") $msg_new_path=$msg_path;
		if($msg_w==0){
			$lng_w=$this->config["resize_w"];
		}else{
			$lng_w=$msg_w;
		}
		if($msg_h==0){
			$lng_h=$this->config["resize_h"];
		}else{
			$lng_h=$msg_h;
		}
		$msg_info=parent::on_resize($msg_path,$lng_w,$lng_h,$msg_new_path);
		return $msg_info;
	}

	function on_chk_resize($msg_path){
		$lng_size=800;
		if(isset($this->config["pic_max_size"]) && is_numeric($this->config["pic_max_size"]) ) $lng_size=$this->config["pic_max_size"];
		if($lng_size<1) return;
		$msg_info=parent::on_resize($msg_path,$lng_size,0,$msg_path);
	}
	function init_config()
	{
		global $obj_tab_sys_config;
		$arr_cfg_other=$obj_tab_sys_config->get_model("other");
		$this->config["allow_watermark"]=0;
		$this->config["watermark_type"]="font";
		$this->config["watermark_font"]="";
		$this->config["watermark_font_size"]="10";
		$this->config["watermark_font_color"]="#ff8800";
		$this->config["watermark_pos"]=9;
		$this->config["watermark_pic"]="";
		$this->config["watermark_quality"]=100;
		$this->config["watermark_font_path"]="";

		$this->config["allow_resize"]=0;
		$this->config["resize_w"]=100;
		$this->config["resize_h"]=75;
		if(is_array($arr_cfg_other))
		{
			if(isset($arr_cfg_other["allow_watermark"])) $this->config["allow_watermark"]=intval($arr_cfg_other["allow_watermark"]);
			if(isset($arr_cfg_other["watermark_type"])) $this->config["watermark_type"]=$arr_cfg_other["watermark_type"];
			if(isset($arr_cfg_other["watermark_font"])) $this->config["watermark_font"]=$arr_cfg_other["watermark_font"];
			if(isset($arr_cfg_other["watermark_font_path"])){
				$this->config["watermark_font_path"]=get_real_path(WEB_ROOT,$arr_cfg_other["watermark_font_path"]);
				if(substr($this->config["watermark_font_path"],0,1)!="/") $this->config["watermark_font_path"]="/".$this->config["watermark_font_path"];
			}
			if(isset($arr_cfg_other["watermark_font_size"])) $this->config["watermark_font_size"]=intval($arr_cfg_other["watermark_font_size"]);
			if(isset($arr_cfg_other["watermark_font_color"])) $this->config["watermark_font_color"]=$arr_cfg_other["watermark_font_color"];
			if(isset($arr_cfg_other["watermark_pos"])) $this->config["watermark_pos"]=intval($arr_cfg_other["watermark_pos"]);
			if(isset($arr_cfg_other["watermark_pic"])) $this->config["watermark_pic"]=get_real_path(WEB_ROOT,$arr_cfg_other["watermark_pic"]);
			if(isset($arr_cfg_other["watermark_quality"])) $this->config["watermark_quality"]=intval($arr_cfg_other["watermark_quality"]);

			if(isset($arr_cfg_other["allow_resize"])) $this->config["allow_resize"]=intval($arr_cfg_other["allow_resize"]);
			if(isset($arr_cfg_other["resize_w"])) $this->config["resize_w"]=intval($arr_cfg_other["resize_w"]);
			if(isset($arr_cfg_other["resize_w"])) $this->config["resize_w"]=intval($arr_cfg_other["resize_w"]);
		}
	}
	function on_watermark($msg_pic)
	{
		$arr_return=array("err"=>"");
		if(!isset($this->config["allow_watermark"])||$this->config["allow_watermark"]!=1){
			$arr_return["err"]="系统未开通水印功能！";
			return $arr_return;
		}
		if($this->config["watermark_type"]=="pic"){				
			$arr_return["err"]=parent::on_pic_watermark($msg_pic,$this->config["watermark_pic"],$this->config["watermark_pos"],$this->config["watermark_quality"]);
		}else{
			if(!is_file(SYS_ROOT.$this->config["watermark_font_path"])){
				$arr_return["err"]="文字水印字体不存在！请从官网下载";
				return $arr_return;
			}
			parent::set_perms("font_path",$this->config["watermark_font_path"]);
			$arr_return["err"]=parent::on_font_watermark($msg_pic,$this->config["watermark_font"],$this->config["watermark_pos"],$this->config["watermark_font_size"],$this->config["watermark_font_color"],$this->config["watermark_quality"]);
		}
		return $arr_return;
	}
}
?>