打印圖片封裝類出現(xiàn)警告怎么辦?
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/2/21
* Time: 17:20
*/
class Image
{
? ?/*內(nèi)存中的圖片*/
? ?private $image;
? ?/*私有的圖片資源信息,不給外部使用*/
? ?private $imageinfo;
? ?/*創(chuàng)建類時打開圖片讀取到內(nèi)存中*/
? ?/**
? ? * Image constructor.
? ? * @param $src
? ? */
? ?public function __construct($src){
? ? ? ?/*獲得圖片資源*/
? ? ? ?$imageinfo=getimagesize($src);
? ? ? ?/*重構(gòu)圖片資源屬性并賦給對象*/
? ? ? ?$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);
? ?}
? ?/*圖片壓縮*/
? ?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;
? ?}
? ?/*快捷打印方式*/
? ?private function printImage($type,$file=null){
? ? ? ?$primg="image{$this->imageinfo['type']}";
? ? ? ?$primg($this->image,$file);
? ?}
? ?/*瀏覽器中顯示圖片*/
? ?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
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/2/21
* Time: 19:18
*/
require_once ("image.php");
$src='001.jpg';
$image=new Image($src);
$image->thumbImage(300,150);
//$image->showImage();
$image->saveImage(xiaoqiche);
Notice: Use of undefined constant xiaoqiche - assumed 'xiaoqiche' in D:\wamp\www\tmlog.com\image\test.php on line?13
求大神解惑~~~~~~
2017-02-21
自己找到BUG了,我在實例化時候需要定義一個變量來傳參數(shù),不能直接將參數(shù)寫進去,會發(fā)出警告。