This commit is contained in:
wangjinlei
2020-11-12 17:15:37 +08:00
parent 824380664c
commit 1abf99316f
893 changed files with 278997 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace tests;
use think\Image;
class CropTest extends TestCase
{
public function testJpeg()
{
$pathname = TEST_PATH . 'tmp/crop.jpg';
$image = Image::open($this->getJpeg());
$image->crop(200, 200, 100, 100, 300, 300)->save($pathname);
$this->assertEquals(300, $image->width());
$this->assertEquals(300, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testPng()
{
$pathname = TEST_PATH . 'tmp/crop.png';
$image = Image::open($this->getPng());
$image->crop(200, 200, 100, 100, 300, 300)->save($pathname);
$this->assertEquals(300, $image->width());
$this->assertEquals(300, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testGif()
{
$pathname = TEST_PATH . 'tmp/crop.gif';
$image = Image::open($this->getGif());
$image->crop(200, 200, 100, 100, 300, 300)->save($pathname);
$this->assertEquals(300, $image->width());
$this->assertEquals(300, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
}

View File

@@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace tests;
use think\Image;
class FlipTest extends TestCase
{
public function testJpeg()
{
$pathname = TEST_PATH . 'tmp/flip.jpg';
$image = Image::open($this->getJpeg());
$image->flip()->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testGif()
{
$pathname = TEST_PATH . 'tmp/flip.gif';
$image = Image::open($this->getGif());
$image->flip(Image::FLIP_Y)->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
}

View File

@@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace tests;
use think\Image;
class InfoTest extends TestCase
{
public function testOpen()
{
$this->setExpectedException("\\think\\image\\Exception");
Image::open('');
}
public function testIllegal()
{
$this->setExpectedException("\\think\\image\\Exception", 'Illegal image file');
Image::open(TEST_PATH . 'images/test.bmp');
}
public function testJpeg()
{
$image = Image::open($this->getJpeg());
$this->assertEquals(800, $image->width());
$this->assertEquals(600, $image->height());
$this->assertEquals('jpeg', $image->type());
$this->assertEquals('image/jpeg', $image->mime());
$this->assertEquals([800, 600], $image->size());
}
public function testPng()
{
$image = Image::open($this->getPng());
$this->assertEquals(800, $image->width());
$this->assertEquals(600, $image->height());
$this->assertEquals('png', $image->type());
$this->assertEquals('image/png', $image->mime());
$this->assertEquals([800, 600], $image->size());
}
public function testGif()
{
$image = Image::open($this->getGif());
$this->assertEquals(380, $image->width());
$this->assertEquals(216, $image->height());
$this->assertEquals('gif', $image->type());
$this->assertEquals('image/gif', $image->mime());
$this->assertEquals([380, 216], $image->size());
}
}

View File

@@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace tests;
use think\Image;
class RotateTest extends TestCase
{
public function testJpeg()
{
$pathname = TEST_PATH . 'tmp/rotate.jpg';
$image = Image::open($this->getJpeg());
$image->rotate(90)->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testGif()
{
$pathname = TEST_PATH . 'tmp/rotate.gif';
$image = Image::open($this->getGif());
$image->rotate(90)->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
}

View File

@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace tests;
use think\File;
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected function getJpeg()
{
return new File(TEST_PATH . 'images/test.jpg');
}
protected function getPng()
{
return new File(TEST_PATH . 'images/test.png');
}
protected function getGif()
{
return new File(TEST_PATH . 'images/test.gif');
}
}

View File

@@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace tests;
use think\Image;
class TextTest extends TestCase
{
public function testJpeg()
{
$pathname = TEST_PATH . 'tmp/text.jpg';
$image = Image::open($this->getJpeg());
$image->text('test', TEST_PATH . 'images/test.ttf', 12)->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testPng()
{
$pathname = TEST_PATH . 'tmp/text.png';
$image = Image::open($this->getPng());
$image->text('test', TEST_PATH . 'images/test.ttf', 12)->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testGif()
{
$pathname = TEST_PATH . 'tmp/text.gif';
$image = Image::open($this->getGif());
$image->text('test', TEST_PATH . 'images/test.ttf', 12)->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
}

View File

@@ -0,0 +1,284 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace tests;
use think\Image;
class ThumbTest extends TestCase
{
public function testJpeg()
{
$pathname = TEST_PATH . 'tmp/thumb.jpg';
//1
$image = Image::open($this->getJpeg());
$image->thumb(200, 200, Image::THUMB_CENTER)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//2
$image = Image::open($this->getJpeg());
$image->thumb(200, 200, Image::THUMB_SCALING)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(150, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//3
$image = Image::open($this->getJpeg());
$image->thumb(200, 200, Image::THUMB_FILLED)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//4
$image = Image::open($this->getJpeg());
$image->thumb(200, 200, Image::THUMB_NORTHWEST)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//5
$image = Image::open($this->getJpeg());
$image->thumb(200, 200, Image::THUMB_SOUTHEAST)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//6
$image = Image::open($this->getJpeg());
$image->thumb(200, 200, Image::THUMB_FIXED)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testPng()
{
$pathname = TEST_PATH . 'tmp/thumb.png';
//1
$image = Image::open($this->getPng());
$image->thumb(200, 200, Image::THUMB_CENTER)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//2
$image = Image::open($this->getPng());
$image->thumb(200, 200, Image::THUMB_SCALING)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(150, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//3
$image = Image::open($this->getPng());
$image->thumb(200, 200, Image::THUMB_FILLED)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//4
$image = Image::open($this->getPng());
$image->thumb(200, 200, Image::THUMB_NORTHWEST)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//5
$image = Image::open($this->getPng());
$image->thumb(200, 200, Image::THUMB_SOUTHEAST)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//6
$image = Image::open($this->getPng());
$image->thumb(200, 200, Image::THUMB_FIXED)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testGif()
{
$pathname = TEST_PATH . 'tmp/thumb.gif';
//1
$image = Image::open($this->getGif());
$image->thumb(200, 200, Image::THUMB_CENTER)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//2
$image = Image::open($this->getGif());
$image->thumb(200, 200, Image::THUMB_SCALING)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(113, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//3
$image = Image::open($this->getGif());
$image->thumb(200, 200, Image::THUMB_FILLED)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//4
$image = Image::open($this->getGif());
$image->thumb(200, 200, Image::THUMB_NORTHWEST)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//5
$image = Image::open($this->getGif());
$image->thumb(200, 200, Image::THUMB_SOUTHEAST)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
//6
$image = Image::open($this->getGif());
$image->thumb(200, 200, Image::THUMB_FIXED)->save($pathname);
$this->assertEquals(200, $image->width());
$this->assertEquals(200, $image->height());
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
}

View File

@@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace tests;
use think\Image;
class WaterTest extends TestCase
{
public function testJpeg()
{
$pathname = TEST_PATH . 'tmp/water.jpg';
$image = Image::open($this->getJpeg());
$image->water(TEST_PATH . 'images/test.gif')->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testPng()
{
$pathname = TEST_PATH . 'tmp/water.png';
$image = Image::open($this->getPng());
$image->water(TEST_PATH . 'images/test.gif')->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
public function testGif()
{
$pathname = TEST_PATH . 'tmp/water.gif';
$image = Image::open($this->getGif());
$image->water(TEST_PATH . 'images/test.jpg')->save($pathname);
$file = new \SplFileInfo($pathname);
$this->assertTrue($file->isFile());
@unlink($pathname);
}
}

View File

@@ -0,0 +1,15 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
define('TEST_PATH', __DIR__ . '/');
// 加载框架基础文件
require __DIR__ . '/../thinkphp/base.php';
\think\Loader::addNamespace('tests', TEST_PATH);
\think\Loader::addNamespace('think', __DIR__ . '/../src/');

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

View File

@@ -0,0 +1,2 @@
*
!.gitignore