->报错怎么解决
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in D:\phpStudy\WWW\image\image.class.php on line 34
34行与老师写的相同,怎么解决
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in D:\phpStudy\WWW\image\image.class.php on line 34
34行与老师写的相同,怎么解决
2016-12-08
你先把代码弄出来
test.php
<?php
require "image.class.php";
/*水印文字*/
$src='002.jpg';
$content='哈哈,HELLO WORLD!!';
$font_url='msyh.ttc';
$size=10;
$angle=10;
$color = array(
0=>0,
1=>0,
2=>0,
3=>50,
);
$local=array(
'X'=>20,
'Y'=>100,
);
/*水印图片*/
$local1=array(
'X'=>0,
'Y'=>0,
);
$source='001.png';
$alpha=30;
$image=new Image($src);
$image->thumb(200,200);
$image->fontMark($content,$font_url,$size,$color,$local,$angle);
$image->imageMark($source,$local1,$alpha);
$image->show();
$image->save(6);
?>
image.class.php
<?php
class image{
private $info;
private $image;
//打开图片
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,$local1,$alpha){
$info2=getimagesize($source);
// 3 水印图片类型
$type2=image_type_to_extension($info2[2],false);
// 4 在内存中创建一个和水印照片一样的图像
$fun2="imagecreatefrom{$type2}";
$water=$fun2($source);
// 5 把水印照片给复制到原图上
imagecopymerge($this->image,$water,$local1['X'],$local1['Y'],0,0,$info2[0],$info2[1],$alpha);
// 6 销毁水印图片
imagedestroy($water);
}
//输出图片到浏览器
public function show(){
header("Content-type:".$this->info['mime']);
$func="image{$this->info['type']}";
$func($this->image);
}
//保存到硬盘中
public function save($newname){
$func="image{$this->info['type']}";
$func($this->image,$newname.'.'.$this->info['type']);
}
//销毁图片
public function __destruct(){
imagedestroy($this->image);
}
}
?>
举报