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

求助:出现错误提示Parse error: syntax error, unexpected '$image' (T_VARIABLE) in ...\test.php on line 4

下面分别是错误提示和我的代码,不知道错在哪了?

57d9174a0001e19a05000081.jpg

57d9174a0001f2da05000136.jpg


正在回答

3 回答

$src = "001.jpg" 赋值语句后少了个分号";"

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

Ymuyi 提问者

非常感谢! 我竟然没看出来啊啊啊
2016-09-16 回复 有任何疑惑可以回复我~
#2

Ymuyi 提问者

不过,又出现了新问题,就是图片没法正常显示额,如下所示
2016-09-16 回复 有任何疑惑可以回复我~
<?php //test.php
	require "image.class.php";
	$src = "001.jpg";
	$image = new Image($src);
	
	//压缩图片
	$image->thumb(300,150);
	$image->show();
?>

<?php //image.class.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[3],$color[4]);
			imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content);
		}
		
		/**
		 *操作图片(添加图片水印)
		 */
		 public function imageMark($source,$local,$alpha)
		{
			$info_mark = getimagesize($source);
			$type_mark = image_type_to_extension($info_mark[2],false);
			$fun_mark = "imagecreatefrom{$type_mark}";
			$image_mark = $fun_mark($source);
			imagecopymerge($this->image,$image_mark,$local['x'],$local['y'],0,0,$info_mark[0],$info_mark[1],$alpha);
			imagedestroy($image_mark);
		}
		 
		/**
		 *在浏览器中输出图片
		 */
		public function show()
		{
			ob_clean();//清空(擦掉)输出缓冲区
			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

goonce

注释掉 thumb() 发现图片依旧无法打印,这就基本可以锁定构造函数或者 show()函数出错,最后看到 show() 函数中 $funs = "image{this->info['type']}" ,this->info['type']==> $this->info['type'](少了美元符号)
2016-09-18 回复 有任何疑惑可以回复我~
#2

Ymuyi 提问者 回复 goonce

谢谢,请收下我的膝盖。查错技能Get!
2016-09-19 回复 有任何疑惑可以回复我~

不过,又出现了新问题,就是图片没法正常显示额,如下所示

http://img1.sycdn.imooc.com//57db4e220001675b01950119.jpg

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

举报

0/150
提交
取消

求助:出现错误提示Parse error: syntax error, unexpected '$image' (T_VARIABLE) in ...\test.php on line 4

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