<?php class Image { private $image; private $imageinfo; public function __construct($src){ $imageinfo=getimagesize($src); $this->imageinfo=array( 'width'=>$imageinfo['0'], 'height'=>$imageinfo['1'], 'type'=>image_type_to_extension($imageinfo['2'],false), 'mime'=>$imageinfo['mime'] ); $this->image=self::creatImage($src); } private function creatImage($src){ $creat="imagecreatefrom{$this->imageinfo['type']}"; return $creat($src); } private function printImage($file=null){ $primg="image{$this->imageinfo['type']}"; $primg($this->image,$file);/**此处是出错误的那一行**/ } public function thumbImage($width,$height){ $image_thumb=imagecreatetruecolor($width,$height); imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->imageinfo['width'],$this->imageinfo['height']); imagedestroy($this->image); $this->image=$image_thumb; } public function fontMark($content,$font_url,$font_size,$color,$local,$angle){ $colortrue=imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]); imagettftext($this->image,$font_size,$angle,$local['x'],$local['y'],$colortrue,$font_url,$content); } public function imageMark($smimgsrc,$local,$alpha){ $info2=getimagesize($smimgsrc); $type2=image_type_to_extension($info2[2],false); $creatsmimg="imagecreatefrom{$type2}"; $water=$creatsmimg($smimgsrc); imagecopymerge($this->image,$water,$local['x'],$local['y'],0,0,$info2[0],$info2[1],$alpha); imagedestroy($water); } /*浏览器中显示图片*/ public function showImage(){ header("Content-type:",$this->imageinfo['mime']); self::printImage($this->image); } /*保存实体文件*/ public function saveImage($picName){ $picturename=$picName.'.'.$this->imageinfo['type']; self::printImage($this->image,$picturename); } /*销毁图片*/ public function __destruct(){ imagedestroy($this->image); } } <?php require_once ("image.php"); $src='001.jpg'; $image=new Image($src); $local=array( 'x'=>'20', 'y'=>'100' ); $smimgsrc="timg.jpg"; $alpha=30; $image->imageMark($smimgsrc,$local,$alpha); $image->showImage(); var_dump($image); Warning: imagejpeg(): supplied resource is not a valid stream resource in D:\wamp\www\tmlog.com\image\image.php on line 39
习惯受伤