搜索
首页php教程PHP源码水印生成缩略图

水印生成缩略图

May 25, 2016 pm 04:58 PM

跳至

class InsertLogo//水印类
  {
  
    private $source;//主图片路径
	private $logo;//水印图片路径
	private $source_type;//主图片类型
	private $logo_type;//水印图片类型
	private $source_width;//主图片宽度
	private $source_height;//主图片高度
	private $logo_width;//水印图片宽度
	private $logo_height;//水印图片高度
	private $tinyImage_width;//略缩图宽
	private $tinyImage_height;//略缩图高
	private $newPicPath;//生成水印图片地址
	private $tinyImagePath;//生成略缩图存放路径
	function __construct($source,$logo)//传入图片路径
	{
	  $this->source=$source;
	  $info=GetImageSize($source);
	  $this->source_width=$info[0];
	  $this->source_height=$info[1];
	  $this->source_type_id=$info[2];
	  $this->source_type=$info['mime'];//其值 1 为 GIF 格式、 2 为 JPEG/JPG 格式、3 为 PNG 格式
	  $this->logo=$logo;
	  $info=GetImageSize($logo);
	  $this->logo_width=$info[0];
	  $this->logo_height=$info[1];
	  $this->logo_type_id=$info[2];
	  $thi->logo_type=$logo['mime'];
	}
	//1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP info[2]图片类型
	function JudgeTypeAndDeal($type,$source)//判断并处理,返回PHP可识别编码
    {
	  if($type==1)//能处理的三种图片。可在上传类限制图片。
	  {
	    return ImageCreateFromGIF($source);	
	  }
	  else if($type==2)
	  {
	    return ImageCreateFromJPEG($source);
	  }
	  else
	  {
	    return ImageCreateFromPNG($source);
	  }
	}
	function CreateLogoImage()//生成水印图
	{
	  $this->source=$this->JudgeTypeAndDeal($this->source_type_id,$this->source);//取得主图片编码
	  $this->logo=$this->JudgeTypeAndDeal($this->logo_type_id,$this->logo);//取得水印编码
	  $x=$this->source_width-$this->logo_width;
	  $y=$this->source_height-$this->logo_height;
	  $w=$this->logo_width;
	  $h=$this->logo_height;
	  /* echo "x=".$x;
	  echo ",y=".$y;
	  echo ",w=".$w;
	  echo ",h=".$h; */
	  ImageCopy($this->source,$this->logo,$x,$y,0,0,$w,$h)or die("fail to combine");
	  $this->newPicPath='App/Upload/image/normal/1108000627/new.jpg';
	  ImageJpeg($this->source,'new.jpg');
      rename('new.jpg',$this->newPicPath);//放到相应文件位置
    } 	 
	function CreateTinyImage()//生成略缩图,生成略缩图原则要控制图片比例,防止比例不协调,可改参数,尝试显示一部分原比例部分图片
	{
	  $TinyImage=imagecreatetruecolor($this->source_width*0.3,$this->source_height*0.3);
	  $this->source=$this->JudgeTypeAndDeal($this->source_type_id,$this->source);//取得主图片编码
	  ImageCopyResized($TinyImage,$this->source,0,0,0,0,$this->source_width*0.3,$this->source_height*0.3,$this->source_width,$this->source_height) or die("fail");
	  $this->tinyImagePath='App/Upload/image/tiny/1108000627/new.jpg';
	  ImageJpeg($TinyImage,'new.jpg');
      rename('new.jpg',$this->tinyImagePath);//放到相应文件位置
	}
  }
  /*添加水印类生成略缩图类END*/

                   

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器