为了账号安全,请及时绑定邮箱和手机立即绑定

Warning: imagecopyresampled() expects parameter 2 to be resource, null given in E:\demo\test01\image\image.class.php on line 21

<?php

class Image{

private $image;

private $info;

public function _construct($src)

{

$info = getimagesize($src);

$this->info = array(

'width'=>$info[0],

'height'=>$info[1],

'type'=>image_type_to_extension($this->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']);

$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);

}

}

?>


正在回答

3 回答

同学你好,代码中有三处地方稍微有点问题:

    1.'type'=>image_type_to_extension($this->info[2],false) 这个地方应该修改为                 'type'=>image_type_to_extension($info[2],false),因为这个时候我们只有$info还没有$this->info;

    2.构造函数和析构函数前面的下滑线是两根,也就是 __construct和__destruct.

希望我的回答对你有帮助,谢谢

2 回复 有任何疑惑可以回复我~
#1

wangping1985 提问者

谢谢老师
2015-02-26 回复 有任何疑惑可以回复我~
#2

wangping1985 提问者

非常感谢!
2015-02-26 回复 有任何疑惑可以回复我~

帮解决

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Warning: imagecopyresampled() expects parameter 2 to be resource, null given in E:\demo\test01\image\image.class.php on line 21

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信