图片处理驱动抛出异常添加命名空间

This commit is contained in:
麦当苗儿
2013-04-16 11:10:17 +08:00
parent 163adf6dc4
commit 20741c2376
3 changed files with 36 additions and 36 deletions

View File

@@ -38,14 +38,14 @@ class Gd{
*/
public function open($imgname){
//检测图像文件
if(!is_file($imgname)) throw new Exception('不存在的图像文件');
if(!is_file($imgname)) throw new \Exception('不存在的图像文件');
//获取图像信息
$info = getimagesize($imgname);
//检测图像合法性
if(false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))){
throw new Exception('非法图像文件');
throw new \Exception('非法图像文件');
}
//设置图像信息
@@ -108,7 +108,7 @@ class Gd{
* @return integer 图像宽度
*/
public function width(){
if(empty($this->im)) throw new Exception('没有指定图像资源');
if(empty($this->im)) throw new \Exception('没有指定图像资源');
return $this->info['width'];
}
@@ -117,7 +117,7 @@ class Gd{
* @return integer 图像高度
*/
public function height(){
if(empty($this->im)) throw new Exception('没有指定图像资源');
if(empty($this->im)) throw new \Exception('没有指定图像资源');
return $this->info['height'];
}
@@ -126,7 +126,7 @@ class Gd{
* @return string 图像类型
*/
public function type(){
if(empty($this->im)) throw new Exception('没有指定图像资源');
if(empty($this->im)) throw new \Exception('没有指定图像资源');
return $this->info['type'];
}
@@ -135,7 +135,7 @@ class Gd{
* @return string 图像MIME类型
*/
public function mime(){
if(empty($this->im)) throw new Exception('没有指定图像资源');
if(empty($this->im)) throw new \Exception('没有指定图像资源');
return $this->info['mime'];
}
@@ -144,7 +144,7 @@ class Gd{
* @return array 图像尺寸
*/
public function size(){
if(empty($this->im)) throw new Exception('没有指定图像资源');
if(empty($this->im)) throw new \Exception('没有指定图像资源');
return [$this->info['width'], $this->info['height']];
}
@@ -158,7 +158,7 @@ class Gd{
* @param integer $height 图像保存高度
*/
public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null){
if(empty($this->im)) throw new Exception('没有可以被裁剪的图像资源');
if(empty($this->im)) throw new \Exception('没有可以被裁剪的图像资源');
//设置保存尺寸
empty($width) && $width = $w;
@@ -191,7 +191,7 @@ class Gd{
* @param integer $type 缩略图裁剪类型
*/
public function thumb($width, $height, $type = THINKIMAGE_THUMB_SCALE){
if(empty($this->im)) throw new Exception('没有可以被缩略的图像资源');
if(empty($this->im)) throw new \Exception('没有可以被缩略的图像资源');
//原图宽度和高度
$w = $this->info['width'];
@@ -286,7 +286,7 @@ class Gd{
break;
default:
throw new Exception('不支持的缩略图裁剪类型');
throw new \Exception('不支持的缩略图裁剪类型');
}
/* 裁剪图像 */
@@ -302,13 +302,13 @@ class Gd{
*/
public function water($source, $locate = THINKIMAGE_WATER_SOUTHEAST){
//资源检测
if(empty($this->im)) throw new Exception('没有可以被添加水印的图像资源');
if(!is_file($source)) throw new Exception('水印图像不存在');
if(empty($this->im)) throw new \Exception('没有可以被添加水印的图像资源');
if(!is_file($source)) throw new \Exception('水印图像不存在');
//获取水印图像信息
$info = getimagesize($source);
if(false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))){
throw new Exception('非法水印文件');
throw new \Exception('非法水印文件');
}
//创建水印图像资源
@@ -378,7 +378,7 @@ class Gd{
if(is_array($locate)){
list($x, $y) = $locate;
} else {
throw new Exception('不支持的水印位置类型');
throw new \Exception('不支持的水印位置类型');
}
}
@@ -415,8 +415,8 @@ class Gd{
public function text($text, $font, $size, $color = '#00000000',
$locate = THINKIMAGE_WATER_SOUTHEAST, $offset = 0, $angle = 0){
//资源检测
if(empty($this->im)) throw new Exception('没有可以被写入文字的图像资源');
if(!is_file($font)) throw new Exception("不存在的字体文件:{$font}");
if(empty($this->im)) throw new \Exception('没有可以被写入文字的图像资源');
if(!is_file($font)) throw new \Exception("不存在的字体文件:{$font}");
//获取文字信息
$info = imagettfbbox($size, $angle, $font, $text);
@@ -489,7 +489,7 @@ class Gd{
$x += $posx;
$y += $posy;
} else {
throw new Exception('不支持的文字位置类型');
throw new \Exception('不支持的文字位置类型');
}
}
@@ -510,7 +510,7 @@ class Gd{
$color[3] = 0;
}
} elseif (!is_array($color)) {
throw new Exception('错误的颜色值');
throw new \Exception('错误的颜色值');
}
do{