mirror of
https://github.com/Intervention/image.git
synced 2025-09-08 21:20:46 +02:00
added anchor param to insert method
This commit is contained in:
@@ -430,9 +430,206 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
||||
|
||||
public function testInsertImage()
|
||||
{
|
||||
$img = $this->getTestImage();
|
||||
$img->insert('public/test.jpg', 10, 10);
|
||||
$img = Image::canvas(32, 32, '#ff0000'); // create canvas
|
||||
$watermark = Image::canvas(16, 16, '#0000ff'); // create watermark
|
||||
|
||||
// top-left anchor
|
||||
$img->insert($watermark, 0, 0, 'top-left');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(0, 0, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(16, 16, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// top-left anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'top-left');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#ff0000', $img->pickColor(9, 9, 'hex'));
|
||||
$this->assertEquals('#0000ff', $img->pickColor(10, 10, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// top anchor
|
||||
$img->insert($watermark, 0, 0, 'top');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#ff0000', $img->pickColor(0, 0, 'hex'));
|
||||
$this->assertEquals('#0000ff', $img->pickColor(23, 15, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// top anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'top');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(18, 10, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(31, 26, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// top-right anchor
|
||||
$img->insert($watermark, 0, 0, 'top-right');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#ff0000', $img->pickColor(15, 0, 'hex'));
|
||||
$this->assertEquals('#0000ff', $img->pickColor(31, 0, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// top-right anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'top-right');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#ff0000', $img->pickColor(6, 9, 'hex'));
|
||||
$this->assertEquals('#0000ff', $img->pickColor(21, 25, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// left anchor
|
||||
$img->insert($watermark, 0, 0, 'left');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(15, 23, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(0, 7, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// left anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'left');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(25, 31, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(10, 17, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// right anchor
|
||||
$img->insert($watermark, 0, 0, 'right');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(31, 23, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(15, 15, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// right anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'right');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(21, 31, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(5, 18, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// bottom-left anchor
|
||||
$img->insert($watermark, 0, 0, 'bottom-left');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(15, 31, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(0, 15, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// bottom-left anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'bottom-left');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(10, 21, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(9, 20, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// bottom anchor
|
||||
$img->insert($watermark, 0, 0, 'bottom');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(8, 16, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(8, 15, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// bottom anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'bottom');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(18, 21, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(17, 21, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// bottom-right anchor
|
||||
$img->insert($watermark, 0, 0, 'bottom-right');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(16, 16, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(15, 16, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// bottom-right anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'bottom-right');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(21, 21, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(22, 22, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// center anchor
|
||||
$img->insert($watermark, 0, 0, 'center');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(23, 23, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(8, 7, 'hex'));
|
||||
$img->reset();
|
||||
|
||||
// center anchor coordinates
|
||||
$img->insert($watermark, 10, 10, 'center');
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$this->assertEquals('#0000ff', $img->pickColor(31, 31, 'hex'));
|
||||
$this->assertEquals('#ff0000', $img->pickColor(18, 17, 'hex'));
|
||||
$img->reset();
|
||||
}
|
||||
|
||||
public function testOpacity()
|
||||
|
Reference in New Issue
Block a user