当前位置: 首页 >
2007年12月26日发布的所有文章
-
一个简单的图片水印的类
PHP代码- /************************************************/
- /*功能:添加图片水印 */
- /*作者:还珠楼主 */
- /*Email:dongxin1390008@163.com */
- class digital
- {
- public $water_w,$water_h;//水印的宽,高
- public $des_w,$des_h;//目标图片的宽高
- public $pos_x,$pos_y;//落点坐标
- public $water_url;//水印URL
- public $des_url;//目标URL
- public $water_info;//水印的基本信息
- public $des_info;//目标图片信息
- public $des,$water;
- function __construct($des_url,$water_url=“images/dig3.png”)
- {
- $this->water=imagecreatefrompng($water_url);
- $this->des=imagecreatefromjpeg($des_url);
- $this->water_info=$this->getXY($water_url);
- $this->des_info=$this->getXY($des_url);
- $this->water_w=$this->water_info[0];
- $this->water_h=$this->water_info[1];
- $this->des_w=$this->des_info[0];
- $this->des_h=$this->des_info[1];
- $this->pos_x=5;
- $this->pos_y=5;
- }
- function getXY($img)
- {
- return getimagesize($img);
- }
- function addDigital($br=true,$bl=false,$tl=false,$tr=false,$mid=false)
- {
- /***************bootom-right**********/
- if($br)
- {
- $this->pos_x=$this->des_w-$this->water_w;
- $this->pos_y=$this->des_h-$this->water_h;
- imagecopymerge($this->des,$this->water,$this->pos_x,$this->pos_y,0,0,$this->water_w,$this->water_h,100);
- }
- /************bottom-left****************/
- if($bl)
- {
- $this->pos_y=$this->des_h-$this->water_h;
- imagecopymerge($this->des,$this->water,0,$this->pos_y,0,0,$this->water_w,$this->water_h,100);
- }
- /**************top-left******************/
- if($tl)
- {
- imagecopymerge($this->des,$this->water,0,0,0,0,$this->water_w,$this->water_h,100);
- }
- /******************top-right************/
- if($tr)
- {
- $this->pos_x=$this->des_w-$this->water_w;
- imagecopymerge($this->des,$this->water,$this->pos_x,0,0,0,$this->water_w,$this->water_h,100);
- }
- /********************middle************/
- if($mid)
- {
- $this->pos_x=($this->des_w-$this->water_w)/2;
- $this->pos_y=($this->des_h-$this->water_h)/2;
- imagecopymerge($this->des,$this->water,$this->pos_x,$this->pos_y,0,0,$this->water_w,$this->water_h,100);
- }
- imagejpeg($this->des);
- header(“Content-type: image/jpeg”);
- }
- }
- ?>
PHP代码- include_once(“function/digital_class.php”);
- $dig=new digital(“images/2.jpg”);
- $dig->addDigital(true,false,false,false,false);
- ?>