->報錯怎么解決
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
舉報
2016-12-12
這是我的代碼? 運行沒有問題
2016-12-12
你先把代碼弄出來
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 在內(nèi)存中創(chuàng)建一個和水印照片一樣的圖像
? ??? ?$fun2="imagecreatefrom{$type2}";
? ??? ?$water=$fun2($source);
?? ?// 5 把水印照片給復(fù)制到原圖上
? ??? ?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);
? }
? }
?>