蓦默
你require那里的类名字都不对吧
qq_涐姓董卻卟懂伱吢_03641575
这里出错了,不用引号
慕粉4279450
你看一下这句话
'type'=>image_type_to_extension($info[2],false),//改成这样就好了
tangly3
知道了
慕雪5265399
嗯,有什么问题吗?
侠客岛的含笑
40行代码有问题 header('Content-type:',$this->info['mime']);
应该是 header('Content-type:'.$this->info['mime']);
如何还是不行就试试这个
<?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($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 fontMark($content,$font_url,$size,$color,$local,$angle){
$col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);
imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content);
}
/*添加图片水印*/
public function imageMark($source,$local,$alpha){
$info2 = getimagesize($source);
$type2 = image_type_to_extension($info2[2],false);
$fun2 = "imagecreatefrom{$type2}";
$water = $fun2($source);
imagecopymerge($this->image,$water,$local['x'],$local['y'],0,0,$info2[0],$info2[1],$alpha);
imagedestroy($water);
}
/*输出图片*/
public function show(){
header("content-type:".$this->info['mime']);
$funs = "image{$this->info['type']}";
$funs($this->image);
}
/*保存图片*/
public function save($newname){
$funs = "image{$this->info['type']}";
$funs($this->image,$newname.'.'.$this->info['type']);
}
/*销毁图片*/
public function __destruct(){
imagedestroy($this->image);
}
}
?>
木上草
自己找到BUG了,我在实例化时候需要定义一个变量来传参数,不能直接将参数写进去,会发出警告。
weibo_蓉芳107_03763669
$image->save(image/newthumb);
weibo_米兰达小包子_04386043
这是我的代码 运行没有问题
qq_丶莫须有_04129249
查看hearde里面是否填写正确
纯正苏打水
dreamweaver敲得
用sublime找到答案了。。。打重复了s
public function __consstruct($src){
Ymuyi
$src = "001.jpg" 赋值语句后少了个分号";"
ilovemooc
发现问题所在,原来是类方法中把图像输出格式搞错了,imagepng比同尺寸的imagejpeg大很多
了吾欲前行
Mr_Been
请问一下怎么改的
Junting
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($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($newname){
$funs = "image{$this->info['type']}";
$funs($this->image,$newname.'.'.$this->info['type']);
}
//销毁图片
public function __destruct()
{
imagedestroy($this->image);
}
}
?>
Junting
Junting
孟子烨
qq_锋_2
//打开图片
public function ww($src){应为构造函数,调用类的 时候自动执行,你没有,所以,找不到资源
阎涛TKD
没法看就不看了,看多了心烦,心累
QQ王道
清明居士
对啊,所以他是先销毁的,完了再赋值。
王凯1994
'type'=>image_type_to_extension($this->info[2],false),
'type'=>image_type_to_extension($info[2],false),
wangping1985
同学你好,代码中有三处地方稍微有点问题:
1.'type'=>image_type_to_extension($this->info[2],false) 这个地方应该修改为 'type'=>image_type_to_extension($info[2],false),因为这个时候我们只有$info还没有$this->info;
2.构造函数和析构函数前面的下滑线是两根,也就是 __construct和__destruct.
希望我的回答对你有帮助,谢谢