为了账号安全,请及时绑定邮箱和手机立即绑定

求正确代码?我这个不对啊

 <?php
	class Image{
		/**
		*内存中的图片
		*/
		private $image;
		/**
		 *	图片的基本信息
		*/
		 private $info;
		 /**
		 *	打开一张图片,读取到内存中
		 */
		public function __construct($src){
			$info = getimagesize($src);
			$this->info = array(
				'width' => $info[0],
				'height' => $info[1],
				'type' => image_type_to_extension($info[2],false),
				'mime' => $info['mime']
				);
			$fun = "imagecreatefrom{$this->info['type']}";
			$this->image = $fun($src); 
		}
		/**
		* 操作图片(压缩)
		*/
		public function thumb($width,$height){
			$image_thumb = imagecreatetruecolor($width,$height);
			imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']);
			imagedestroy($this->image);
			$this->image = $image_thumb;
		}

		/**
		*	输出图片
		*/
		public function show(){
			header('Content-type:',$this->info['mime']);
			$funs = "image{$this->info['type']}";
			$funs($this->image);
		}

		/**
		*	把图片保存在硬盘里
		*/
		public function save($newname){
			$funs = "image{$this->info['type']}";
			$funs($this->image,$newname.'.'.$this->info['type']);
		}

		/**
		* 销毁图片
		*/
		public function __destruct(){
			imagedestroy($this->image);
		}

	}
?>


正在回答

1 回答

40行代码有问题   header('Content-type:',$this->info['mime']);

应该是 header('Content-type:'.$this->info['mime']);

如何还是不行就试试这个

<?php
	class Image{
	        /*内存中的图片*/
		private $image;
		/*图片的基本信息*/
		private $info;
		/* 打开一张图片,读取到内存中*/
		public function __construct($src){
			$info = getimagesize($src);
			$this->info = array(
				'width' => $info[0],
				'height' => $info[1],
				'type' =>image_type_to_extension($info[2],false),
				'mime' => $info['mime']
			);
			$fun = "imagecreatefrom{$this->info['type']}";
			$this->image = $fun($src);
		}

		/*压缩图片*/
		public function thumb($width,$height){
			$image_thumb = imagecreatetruecolor($width,$height);
			imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']);
			imagedestroy($this->image);
			$this->image=$image_thumb;
		}
		
		/*添加文字水印*/
		public function fontMark($content,$font_url,$size,$color,$local,$angle){
			$col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);
			imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content);
		}
		
		/*添加图片水印*/
		public function imageMark($source,$local,$alpha){
			$info2 = getimagesize($source);
			$type2 = image_type_to_extension($info2[2],false);
			$fun2 = "imagecreatefrom{$type2}";
			$water = $fun2($source);
			imagecopymerge($this->image,$water,$local['x'],$local['y'],0,0,$info2[0],$info2[1],$alpha);
			imagedestroy($water);
		}

		/*输出图片*/
		public function show(){
			header("content-type:".$this->info['mime']);
			$funs = "image{$this->info['type']}";
			$funs($this->image);
		}
		/*保存图片*/
		public function save($newname){
			$funs = "image{$this->info['type']}";
			$funs($this->image,$newname.'.'.$this->info['type']);	
		}
		/*销毁图片*/
		public function __destruct(){
			imagedestroy($this->image);
		}
	}
?>


0 回复 有任何疑惑可以回复我~
#1

侠客岛的含笑 提问者

非常感谢!
2017-03-24 回复 有任何疑惑可以回复我~
#2

语沫流逝 回复 侠客岛的含笑 提问者

不用谢!!!!!
2017-03-24 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求正确代码?我这个不对啊

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信