Ymuyi
2016-09-14 17:49
下面分别是错误提示和我的代码,不知道错在哪了?


$src = "001.jpg" 赋值语句后少了个分号";"
<?php //test.php
require "image.class.php";
$src = "001.jpg";
$image = new Image($src);
//压缩图片
$image->thumb(300,150);
$image->show();
?>
<?php //image.class.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[3],$color[4]);
imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content);
}
/**
*操作图片(添加图片水印)
*/
public function imageMark($source,$local,$alpha)
{
$info_mark = getimagesize($source);
$type_mark = image_type_to_extension($info_mark[2],false);
$fun_mark = "imagecreatefrom{$type_mark}";
$image_mark = $fun_mark($source);
imagecopymerge($this->image,$image_mark,$local['x'],$local['y'],0,0,$info_mark[0],$info_mark[1],$alpha);
imagedestroy($image_mark);
}
/**
*在浏览器中输出图片
*/
public function show()
{
ob_clean();//清空(擦掉)输出缓冲区
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);
}
}
?>
不过,又出现了新问题,就是图片没法正常显示额,如下所示

GD库实现图片水印与缩略图
19007 学习 · 168 问题
相似问题