问答详情
源自:5-1 封装成类—压缩图片

有错误求解答 代码点开看

<?php

class Image {

/*内存中的图片*/

private $image;

/*图片的基本信息*/

private $info;

/*打开一张图片,读取到内存中*/

public function __consstruct($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 show(){

header("Content-type:".$this->info['mime']);

$funs = "image{$this->info['type']}";

$funs($this->image);

}

/*保存图片*/

public function save($newimg){

$func = "image{$this->info['type']}";

$func($this->image,image,$newimg.'.'.$this->info['type']);

}

/*销毁图片*/

public function __destruct(){

imagedestroy($this->image);

}

}

?>






<?php

require "image_class.php";

$src = '001.png';

$image = new Image('$src');

$image->thumb(300,200);

$image->show();

?>


提问者:qq_涐姓董卻卟懂伱吢_03641575 2017-08-04 14:21

个回答

  • qq_瑞飘尘心_0
    2017-08-25 18:17:15

    http://img.mukewang.com/599ff9080001702d03390181.jpg这里出错了,不用引号