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