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);
}
}
?>
2015-02-26
同學(xué)你好,代碼中有三處地方稍微有點(diǎn)問題:
????1.'type'=>image_type_to_extension($this->info[2],false) 這個(gè)地方應(yīng)該修改為???????????????? 'type'=>image_type_to_extension($info[2],false),因?yàn)檫@個(gè)時(shí)候我們只有$info還沒有$this->info;
????2.構(gòu)造函數(shù)和析構(gòu)函數(shù)前面的下滑線是兩根,也就是 __construct和__destruct.
希望我的回答對你有幫助,謝謝
2015-02-25
幫解決