Skip to content

Commit

Permalink
Image改到think命名空间下
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Jul 13, 2016
1 parent 9ad3215 commit e29b889
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
## 使用

~~~
$image = \think\image\Image::open('./image.jpg');
$image = \think\Image::open('./image.jpg');
或者
$image = \think\image\Image::open(request()->file('image'));
$image = \think\Image::open(request()->file('image'));
$image->crop(...)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"autoload": {
"psr-4": {
"think\\image\\": "src"
"think\\": "src"
}
}
}
25 changes: 13 additions & 12 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------

namespace think\image;
namespace think;

use think\image\gif\Gif;
use think\image\Exception as ImageException;

class Image
{
Expand Down Expand Up @@ -58,7 +59,7 @@ protected function __construct(\SplFileInfo $file)

//检测图像合法性
if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
throw new Exception('Illegal image file');
throw new ImageException('Illegal image file');
}

//设置图像信息
Expand All @@ -79,7 +80,7 @@ protected function __construct(\SplFileInfo $file)
}

if (empty($this->im)) {
throw new Exception('Failed to create image resources!');
throw new ImageException('Failed to create image resources!');
}

}
Expand All @@ -95,7 +96,7 @@ public static function open($file)
$file = new \SplFileInfo($file);
}
if (!$file->isFile()) {
throw new Exception('image file not exist');
throw new ImageException('image file not exist');
}
return new self($file);
}
Expand Down Expand Up @@ -301,7 +302,7 @@ public function thumb($width, $height, $type = self::THUMB_SCALING)
$x = $y = 0;
break;
default:
throw new Exception('不支持的缩略图裁剪类型');
throw new ImageException('不支持的缩略图裁剪类型');
}
/* 裁剪图像 */
$this->crop($w, $h, $x, $y, $width, $height);
Expand All @@ -319,12 +320,12 @@ public function thumb($width, $height, $type = self::THUMB_SCALING)
public function water($source, $locate = self::WATER_SOUTHEAST)
{
if (!is_file($source)) {
throw new Exception('水印图像不存在');
throw new ImageException('水印图像不存在');
}
//获取水印图像信息
$info = getimagesize($source);
if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
throw new Exception('非法水印文件');
throw new ImageException('非法水印文件');
}
//创建水印图像资源
$fun = 'imagecreatefrom' . image_type_to_extension($info[2], false);
Expand Down Expand Up @@ -382,7 +383,7 @@ public function water($source, $locate = self::WATER_SOUTHEAST)
if (is_array($locate)) {
list($x, $y) = $locate;
} else {
throw new Exception('不支持的水印位置类型');
throw new ImageException('不支持的水印位置类型');
}
}
do {
Expand Down Expand Up @@ -414,14 +415,14 @@ public function water($source, $locate = self::WATER_SOUTHEAST)
* @param integer $angle 文字倾斜角度
*
* @return $this
* @throws Exception
* @throws ImageException
*/
public function text($text, $font, $size, $color = '#00000000',
$locate = self::WATER_SOUTHEAST, $offset = 0, $angle = 0)
{

if (!is_file($font)) {
throw new Exception("不存在的字体文件:{$font}");
throw new ImageException("不存在的字体文件:{$font}");
}
//获取文字信息
$info = imagettfbbox($size, $angle, $font, $text);
Expand Down Expand Up @@ -483,7 +484,7 @@ public function text($text, $font, $size, $color = '#00000000',
$x += $posx;
$y += $posy;
} else {
throw new Exception('不支持的文字位置类型');
throw new ImageException('不支持的文字位置类型');
}
}
/* 设置偏移量 */
Expand All @@ -502,7 +503,7 @@ public function text($text, $font, $size, $color = '#00000000',
$color[3] = 0;
}
} elseif (!is_array($color)) {
throw new Exception('错误的颜色值');
throw new ImageException('错误的颜色值');
}
do {
/* 写入文字 */
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/CropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// +----------------------------------------------------------------------
namespace tests;

use think\image\Image;
use think\Image;

class CropTest extends TestCase
{
Expand Down
3 changes: 1 addition & 2 deletions tests/InfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
// +----------------------------------------------------------------------
namespace tests;

use think\image\Exception;
use think\image\Image;
use think\Image;

class InfoTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// +----------------------------------------------------------------------
namespace tests;

use think\image\Image;
use think\Image;

class TextTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/ThumbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// +----------------------------------------------------------------------
namespace tests;

use think\image\Image;
use think\Image;

class ThumbTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/WaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// +----------------------------------------------------------------------
namespace tests;

use think\image\Image;
use think\Image;

class WaterTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
// 加载框架基础文件
require __DIR__ . '/../thinkphp/base.php';
\think\Loader::addNamespace('tests', TEST_PATH);
\think\Loader::addNamespace('think\\image', __DIR__ . '/../src/');
\think\Loader::addNamespace('think', __DIR__ . '/../src/');

0 comments on commit e29b889

Please sign in to comment.