Skip to content

Commit

Permalink
Revert "Rename methods of ImageInterface"
Browse files Browse the repository at this point in the history
This reverts commit ba01e87.
  • Loading branch information
olivervogel committed Oct 7, 2023
1 parent 4ff9abd commit d9f4c24
Show file tree
Hide file tree
Showing 42 changed files with 121 additions and 138 deletions.
4 changes: 2 additions & 2 deletions src/Drivers/Abstract/AbstractImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public function sharpen(int $amount = 10): ImageInterface
);
}

public function getColors(int $x, int $y): CollectionInterface
public function pickColors(int $x, int $y): CollectionInterface
{
$colors = new Collection();
foreach ($this as $key => $frame) {
$colors->push($this->getColor($x, $y, $key));
$colors->push($this->pickColor($x, $y, $key));
}

return $colors;
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Gd/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getHeight(): int
return imagesy($this->getFrame()->getCore());
}

public function getColor(int $x, int $y, int $frame_key = 0): ?ColorInterface
public function pickColor(int $x, int $y, int $frame_key = 0): ?ColorInterface
{
if ($frame = $this->getFrame($frame_key)) {
return new Color(imagecolorat($frame->getCore(), $x, $y));
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Imagick/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function getHeight(): int
return $this->getFrame()->getCore()->getImageHeight();
}

public function getColor(int $x, int $y, int $frame_key = 0): ?ColorInterface
public function pickColor(int $x, int $y, int $frame_key = 0): ?ColorInterface
{
if ($frame = $this->getFrame($frame_key)) {
return new Color($frame->getCore()->getImagePixelColor($x, $y));
Expand Down
23 changes: 3 additions & 20 deletions src/Interfaces/ImageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Intervention\Image\Interfaces;

use Countable;
use Intervention\Image\Collection;
use Intervention\Image\EncodedImage;
use Traversable;

Expand Down Expand Up @@ -137,26 +138,8 @@ public function toAvif(): EncodedImage;
*/
public function toPng(): EncodedImage;

/**
* Return color of pixel at the given position of the image
* For animated image pass the key of the animation frame.
*
* @param int $x
* @param int $y
* @param int $frame_key
* @return null|ColorInterface
*/
public function getColor(int $x, int $y, int $frame_key = 0): ?ColorInterface;

/**
* Return a collection with the color of the pixel at the given position
* For animated images all pixel colors for all frames are returned.
*
* @param int $x
* @param int $y
* @return CollectionInterface
*/
public function getColors(int $x, int $y): CollectionInterface;
public function pickColor(int $x, int $y, int $frame_key = 0): ?ColorInterface;
public function pickColors(int $x, int $y): CollectionInterface;

/**
* Draw text on image
Expand Down
6 changes: 3 additions & 3 deletions tests/Drivers/Abstract/AbstractImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ public function testSharpen(): void
$this->assertInstanceOf(ImageInterface::class, $result);
}

public function testGetColors(): void
public function testPickColors(): void
{
$color = Mockery::mock(ColorInterface::class);
$img = $this->abstractImageMock();
$img->shouldReceive('getColor')->times(3)->andReturn($color);
$result = $img->getColors(1, 2);
$img->shouldReceive('pickColor')->times(3)->andReturn($color);
$result = $img->pickColors(1, 2);
$this->assertInstanceOf(Collection::class, $result);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Drivers/Gd/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,33 @@ public function testGetSize(): void
$this->assertInstanceOf(Rectangle::class, $this->image->getSize());
}

public function testGetColor(): void
public function testPickColor(): void
{
$color = $this->image->getColor(0, 0);
$color = $this->image->pickColor(0, 0);
$this->assertInstanceOf(Color::class, $color);
$this->assertEquals(255, $color->red());
$this->assertEquals(0, $color->green());
$this->assertEquals(0, $color->blue());

$color = $this->image->getColor(0, 0, 1);
$color = $this->image->pickColor(0, 0, 1);
$this->assertInstanceOf(Color::class, $color);
$this->assertEquals(0, $color->red());
$this->assertEquals(255, $color->green());
$this->assertEquals(0, $color->blue());

$color = $this->image->getColor(0, 0, 2);
$color = $this->image->pickColor(0, 0, 2);
$this->assertInstanceOf(Color::class, $color);
$this->assertEquals(0, $color->red());
$this->assertEquals(0, $color->green());
$this->assertEquals(255, $color->blue());

$color = $this->image->getColor(0, 0, 3);
$color = $this->image->pickColor(0, 0, 3);
$this->assertNull($color);
}

public function testGetColors(): void
public function testPickColors(): void
{
$colors = $this->image->getColors(0, 0);
$colors = $this->image->pickColors(0, 0);
$this->assertInstanceOf(Collection::class, $colors);
$this->assertCount(3, $colors);

Expand Down
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/BlurModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class BlurModifierTest extends TestCase
public function testColorChange(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$image->modify(new BlurModifier(30));
$this->assertEquals('4fa68d', $image->getColor(14, 14)->toHex());
$this->assertEquals('4fa68d', $image->pickColor(14, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/BrightnessModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class BrightnessModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$image->modify(new BrightnessModifier(30));
$this->assertEquals('4cfaff', $image->getColor(14, 14)->toHex());
$this->assertEquals('4cfaff', $image->pickColor(14, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/ContrastModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ContrastModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$image->modify(new ContrastModifier(30));
$this->assertEquals('00ceff', $image->getColor(14, 14)->toHex());
$this->assertEquals('00ceff', $image->pickColor(14, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/DrawEllipseModiferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class DrawEllipseModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$drawable = new Ellipse(10, 10);
$drawable->background('b53717');
$image->modify(new DrawEllipseModifier(new Point(14, 14), $drawable));
$this->assertEquals('b53717', $image->getColor(14, 14)->toHex());
$this->assertEquals('b53717', $image->pickColor(14, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/DrawLineModiferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class DrawLineModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$line = new Line(new Point(0, 0), new Point(10, 0), 4);
$line->background('b53517');
$image->modify(new DrawLineModifier(new Point(0, 0), $line));
$this->assertEquals('b53517', $image->getColor(0, 0)->toHex());
$this->assertEquals('b53517', $image->pickColor(0, 0)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/DrawPixelModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class DrawPixelModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$image->modify(new DrawPixelModifier(new Point(14, 14), 'ffffff'));
$this->assertEquals('ffffff', $image->getColor(14, 14)->toHex());
$this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/DrawPolygonModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class DrawPolygonModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$drawable = new Polygon([new Point(0, 0), new Point(15, 15), new Point(20, 20)]);
$drawable->background('b53717');
$image->modify(new DrawPolygonModifier($drawable));
$this->assertEquals('b53717', $image->getColor(14, 14)->toHex());
$this->assertEquals('b53717', $image->pickColor(14, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/DrawRectangleModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class DrawRectangleModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$rectangle = new Rectangle(300, 200);
$rectangle->background('ffffff');
$image->modify(new DrawRectangleModifier(new Point(14, 14), $rectangle));
$this->assertEquals('ffffff', $image->getColor(14, 14)->toHex());
$this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex());
}
}
16 changes: 8 additions & 8 deletions tests/Drivers/Gd/Modifiers/FillModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ class FillModifierTest extends TestCase
public function testFloodFillColor(): void
{
$image = $this->createTestImage('blocks.png');
$this->assertEquals('0000ff', $image->getColor(420, 270)->toHex());
$this->assertEquals('ff0000', $image->getColor(540, 400)->toHex());
$this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex());
$this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex());
$image->modify(new FillModifier(new Color(13421772), new Point(540, 400)));
$this->assertEquals('0000ff', $image->getColor(420, 270)->toHex());
$this->assertEquals('cccccc', $image->getColor(540, 400)->toHex());
$this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex());
$this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex());
}

public function testFillAllColor(): void
{
$image = $this->createTestImage('blocks.png');
$this->assertEquals('0000ff', $image->getColor(420, 270)->toHex());
$this->assertEquals('ff0000', $image->getColor(540, 400)->toHex());
$this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex());
$this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex());
$image->modify(new FillModifier(new Color(13421772)));
$this->assertEquals('cccccc', $image->getColor(420, 270)->toHex());
$this->assertEquals('cccccc', $image->getColor(540, 400)->toHex());
$this->assertEquals('cccccc', $image->pickColor(420, 270)->toHex());
$this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex());
}
}
8 changes: 4 additions & 4 deletions tests/Drivers/Gd/Modifiers/FitModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public function testModify(): void
$image->modify(new FitModifier(100, 100, 'center'));
$this->assertEquals(100, $image->getWidth());
$this->assertEquals(100, $image->getHeight());
$this->assertColor(255, 0, 0, 1, $image->getColor(90, 90));
$this->assertColor(0, 255, 0, 1, $image->getColor(65, 70));
$this->assertColor(0, 0, 255, 1, $image->getColor(70, 52));
$this->assertTransparency($image->getColor(90, 30));
$this->assertColor(255, 0, 0, 1, $image->pickColor(90, 90));
$this->assertColor(0, 255, 0, 1, $image->pickColor(65, 70));
$this->assertColor(0, 0, 255, 1, $image->pickColor(70, 52));
$this->assertTransparency($image->pickColor(90, 30));
}
}
8 changes: 4 additions & 4 deletions tests/Drivers/Gd/Modifiers/FlipFlopModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ class FlipFlopModifierTest extends TestCase
public function testFlipImage(): void
{
$image = $this->createTestImage('tile.png');
$this->assertEquals('b4e000', $image->getColor(0, 0)->toHex());
$this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex());
$image->modify(new FlipModifier());
$this->assertEquals('000000', $image->getColor(0, 0)->toHex());
$this->assertEquals('000000', $image->pickColor(0, 0)->toHex());
}

public function testFlopImage(): void
{
$image = $this->createTestImage('tile.png');
$this->assertEquals('b4e000', $image->getColor(0, 0)->toHex());
$this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex());
$image->modify(new FlopModifier());
$this->assertEquals('000000', $image->getColor(0, 0)->toHex());
$this->assertEquals('000000', $image->pickColor(0, 0)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/GammaModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class GammaModifierTest extends TestCase
public function testModifier(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(0, 0)->toHex());
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
$image->modify(new GammaModifier(2.1));
$this->assertEquals('00d5f8', $image->getColor(0, 0)->toHex());
$this->assertEquals('00d5f8', $image->pickColor(0, 0)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/GreyscaleModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class GreyscaleModifierTest extends TestCase
public function testColorChange(): void
{
$image = $this->createTestImage('trim.png');
$this->assertFalse($image->getColor(0, 0)->isGreyscale());
$this->assertFalse($image->pickColor(0, 0)->isGreyscale());
$image->modify(new GreyscaleModifier());
$this->assertTrue($image->getColor(0, 0)->isGreyscale());
$this->assertTrue($image->pickColor(0, 0)->isGreyscale());
}
}
8 changes: 4 additions & 4 deletions tests/Drivers/Gd/Modifiers/InvertModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class InvertModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(0, 0)->toHex());
$this->assertEquals('ffa601', $image->getColor(25, 25)->toHex());
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
$this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex());
$image->modify(new InvertModifier());
$this->assertEquals('ff510f', $image->getColor(0, 0)->toHex());
$this->assertEquals('0059fe', $image->getColor(25, 25)->toHex());
$this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex());
$this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex());
}
}
8 changes: 4 additions & 4 deletions tests/Drivers/Gd/Modifiers/PixelateModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class PixelateModifierTest extends TestCase
public function testModify(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(0, 0)->toHex());
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$image->modify(new PixelateModifier(10));
$this->assertEquals('00aef0', $image->getColor(0, 0)->toHex());
$this->assertEquals('6aaa8b', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
$this->assertEquals('6aaa8b', $image->pickColor(14, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/PlaceModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class PlaceModifierTest extends TestCase
public function testColorChange(): void
{
$image = $this->createTestImage('test.jpg');
$this->assertEquals('febc44', $image->getColor(300, 25)->toHex());
$this->assertEquals('febc44', $image->pickColor(300, 25)->toHex());
$image->modify(new PlaceModifier(__DIR__ . '/../../../images/circle.png', 'top-right', 0, 0));
$this->assertEquals('32250d', $image->getColor(300, 25)->toHex());
$this->assertEquals('32250d', $image->pickColor(300, 25)->toHex());
}
}
8 changes: 4 additions & 4 deletions tests/Drivers/Gd/Modifiers/ResizeModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public function testModify(): void
$image->modify(new ResizeModifier(200, 100));
$this->assertEquals(200, $image->getWidth());
$this->assertEquals(100, $image->getHeight());
$this->assertColor(255, 0, 0, 1, $image->getColor(150, 70));
$this->assertColor(0, 255, 0, 1, $image->getColor(125, 70));
$this->assertColor(0, 0, 255, 1, $image->getColor(130, 54));
$transparent = $image->getColor(170, 30);
$this->assertColor(255, 0, 0, 1, $image->pickColor(150, 70));
$this->assertColor(0, 255, 0, 1, $image->pickColor(125, 70));
$this->assertColor(0, 0, 255, 1, $image->pickColor(130, 54));
$transparent = $image->pickColor(170, 30);
$this->assertEquals(2130706432, $transparent->toInt());
$this->assertTransparency($transparent);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Drivers/Gd/Modifiers/SharpenModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SharpenModifierTest extends TestCase
public function testModify(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('60ab96', $image->getColor(15, 14)->toHex());
$this->assertEquals('60ab96', $image->pickColor(15, 14)->toHex());
$image->modify(new SharpenModifier(10));
$this->assertEquals('4daba7', $image->getColor(15, 14)->toHex());
$this->assertEquals('4daba7', $image->pickColor(15, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Imagick/Modifiers/BlurModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class BlurModifierTest extends TestCase
public function testColorChange(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$image->modify(new BlurModifier(30));
$this->assertEquals('42acb2', $image->getColor(14, 14)->toHex());
$this->assertEquals('42acb2', $image->pickColor(14, 14)->toHex());
}
}
4 changes: 2 additions & 2 deletions tests/Drivers/Imagick/Modifiers/BrightnessModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class BrightnessModifierTest extends TestCase
public function testApply(): void
{
$image = $this->createTestImage('trim.png');
$this->assertEquals('00aef0', $image->getColor(14, 14)->toHex());
$this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex());
$image->modify(new BrightnessModifier(30));
$this->assertEquals('39c9ff', $image->getColor(14, 14)->toHex());
$this->assertEquals('39c9ff', $image->pickColor(14, 14)->toHex());
}
}
Loading

0 comments on commit d9f4c24

Please sign in to comment.