mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
图片处理驱动抛出异常添加命名空间
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -41,7 +41,7 @@ class Gif{
|
||||
$this->frames = $de->GIFGetFrames();
|
||||
$this->delays = $de->GIFGetDelays();
|
||||
} catch(Exception $e){
|
||||
throw new Exception("解码GIF图片出错");
|
||||
throw new \Exception("解码GIF图片出错");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Imagick{
|
||||
*/
|
||||
public function open($imgname){
|
||||
//检测图像文件
|
||||
if(!is_file($imgname)) throw new Exception('不存在的图像文件');
|
||||
if(!is_file($imgname)) throw new \Exception('不存在的图像文件');
|
||||
|
||||
//销毁已存在的图像
|
||||
empty($this->im) || $this->im->destroy();
|
||||
@@ -65,7 +65,7 @@ class Imagick{
|
||||
* @param boolean $interlace 是否对JPEG类型图像设置隔行扫描
|
||||
*/
|
||||
public function save($imgname, $type = null, $interlace = true){
|
||||
if(empty($this->im)) throw new Exception('没有可以被保存的图像资源');
|
||||
if(empty($this->im)) throw new \Exception('没有可以被保存的图像资源');
|
||||
|
||||
//设置图片类型
|
||||
if(is_null($type)){
|
||||
@@ -97,7 +97,7 @@ class Imagick{
|
||||
* @return integer 图像宽度
|
||||
*/
|
||||
public function width(){
|
||||
if(empty($this->im)) throw new Exception('没有指定图像资源');
|
||||
if(empty($this->im)) throw new \Exception('没有指定图像资源');
|
||||
return $this->info['width'];
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class Imagick{
|
||||
* @return integer 图像高度
|
||||
*/
|
||||
public function height(){
|
||||
if(empty($this->im)) throw new Exception('没有指定图像资源');
|
||||
if(empty($this->im)) throw new \Exception('没有指定图像资源');
|
||||
return $this->info['height'];
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class Imagick{
|
||||
* @return string 图像类型
|
||||
*/
|
||||
public function type(){
|
||||
if(empty($this->im)) throw new Exception('没有指定图像资源');
|
||||
if(empty($this->im)) throw new \Exception('没有指定图像资源');
|
||||
return $this->info['type'];
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ class Imagick{
|
||||
* @return string 图像MIME类型
|
||||
*/
|
||||
public function mime(){
|
||||
if(empty($this->im)) throw new Exception('没有指定图像资源');
|
||||
if(empty($this->im)) throw new \Exception('没有指定图像资源');
|
||||
return $this->info['mime'];
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ class Imagick{
|
||||
* @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']];
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ class Imagick{
|
||||
* @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;
|
||||
@@ -199,7 +199,7 @@ class Imagick{
|
||||
* @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'];
|
||||
@@ -319,7 +319,7 @@ class Imagick{
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception('不支持的缩略图裁剪类型');
|
||||
throw new \Exception('不支持的缩略图裁剪类型');
|
||||
}
|
||||
|
||||
/* 裁剪图像 */
|
||||
@@ -348,8 +348,8 @@ class Imagick{
|
||||
*/
|
||||
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('水印图像不存在');
|
||||
|
||||
//创建水印图像资源
|
||||
$water = new Imagick(realpath($source));
|
||||
@@ -415,7 +415,7 @@ class Imagick{
|
||||
if(is_array($locate)){
|
||||
list($x, $y) = $locate;
|
||||
} else {
|
||||
throw new Exception('不支持的水印位置类型');
|
||||
throw new \Exception('不支持的水印位置类型');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,8 +459,8 @@ class Imagick{
|
||||
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}");
|
||||
|
||||
//获取颜色和透明度
|
||||
if(is_array($color)){
|
||||
@@ -470,7 +470,7 @@ class Imagick{
|
||||
}
|
||||
$color = '#' . implode('', $color);
|
||||
} elseif(!is_string($color) || 0 !== strpos($color, '#')) {
|
||||
throw new Exception('错误的颜色值');
|
||||
throw new \Exception('错误的颜色值');
|
||||
}
|
||||
$col = substr($color, 0, 7);
|
||||
$alp = strlen($color) == 9 ? substr($color, -2) : 0;
|
||||
@@ -551,7 +551,7 @@ class Imagick{
|
||||
$x += $posx;
|
||||
$y += $posy;
|
||||
} else {
|
||||
throw new Exception('不支持的文字位置类型');
|
||||
throw new \Exception('不支持的文字位置类型');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user