mirror of
https://github.com/Intervention/image.git
synced 2025-08-24 14:32:52 +02:00
Implement __debugInfo() (#1406)
This commit is contained in:
@@ -8,6 +8,7 @@ use Intervention\Image\Exceptions\ColorException;
|
|||||||
use Intervention\Image\Interfaces\ColorChannelInterface;
|
use Intervention\Image\Interfaces\ColorChannelInterface;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||||
|
use ReflectionClass;
|
||||||
|
|
||||||
abstract class AbstractColor implements ColorInterface
|
abstract class AbstractColor implements ColorInterface
|
||||||
{
|
{
|
||||||
@@ -85,6 +86,20 @@ abstract class AbstractColor implements ColorInterface
|
|||||||
return $colorspace->importColor($this);
|
return $colorspace->importColor($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show debug info for the current color
|
||||||
|
*
|
||||||
|
* @return array<string, int>
|
||||||
|
*/
|
||||||
|
public function __debugInfo(): array
|
||||||
|
{
|
||||||
|
return array_reduce($this->channels(), function (array $result, ColorChannelInterface $item) {
|
||||||
|
$key = strtolower((new ReflectionClass($item))->getShortName());
|
||||||
|
$result[$key] = $item->value();
|
||||||
|
return $result;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
|
25
src/Drivers/AbstractFrame.php
Normal file
25
src/Drivers/AbstractFrame.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Intervention\Image\Drivers;
|
||||||
|
|
||||||
|
use Intervention\Image\Interfaces\FrameInterface;
|
||||||
|
|
||||||
|
abstract class AbstractFrame implements FrameInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Show debug info for the current image
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function __debugInfo(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'delay' => $this->delay(),
|
||||||
|
'left' => $this->offsetLeft(),
|
||||||
|
'top' => $this->offsetTop(),
|
||||||
|
'dispose' => $this->dispose(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Intervention\Image\Drivers\Gd;
|
namespace Intervention\Image\Drivers\Gd;
|
||||||
|
|
||||||
use GdImage;
|
use GdImage;
|
||||||
|
use Intervention\Image\Drivers\AbstractFrame;
|
||||||
use Intervention\Image\Exceptions\ColorException;
|
use Intervention\Image\Exceptions\ColorException;
|
||||||
use Intervention\Image\Exceptions\InputException;
|
use Intervention\Image\Exceptions\InputException;
|
||||||
use Intervention\Image\Geometry\Rectangle;
|
use Intervention\Image\Geometry\Rectangle;
|
||||||
@@ -14,7 +15,7 @@ use Intervention\Image\Interfaces\FrameInterface;
|
|||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\SizeInterface;
|
use Intervention\Image\Interfaces\SizeInterface;
|
||||||
|
|
||||||
class Frame implements FrameInterface
|
class Frame extends AbstractFrame implements FrameInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create new frame instance
|
* Create new frame instance
|
||||||
|
@@ -7,6 +7,7 @@ namespace Intervention\Image\Drivers\Imagick;
|
|||||||
use Imagick;
|
use Imagick;
|
||||||
use ImagickException;
|
use ImagickException;
|
||||||
use ImagickPixel;
|
use ImagickPixel;
|
||||||
|
use Intervention\Image\Drivers\AbstractFrame;
|
||||||
use Intervention\Image\Exceptions\InputException;
|
use Intervention\Image\Exceptions\InputException;
|
||||||
use Intervention\Image\Geometry\Rectangle;
|
use Intervention\Image\Geometry\Rectangle;
|
||||||
use Intervention\Image\Image;
|
use Intervention\Image\Image;
|
||||||
@@ -15,7 +16,7 @@ use Intervention\Image\Interfaces\FrameInterface;
|
|||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\SizeInterface;
|
use Intervention\Image\Interfaces\SizeInterface;
|
||||||
|
|
||||||
class Frame implements FrameInterface
|
class Frame extends AbstractFrame implements FrameInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create new frame object
|
* Create new frame object
|
||||||
|
@@ -50,4 +50,17 @@ class EncodedImage extends File implements EncodedImageInterface
|
|||||||
{
|
{
|
||||||
return sprintf('data:%s;base64,%s', $this->mediaType(), base64_encode((string) $this));
|
return sprintf('data:%s;base64,%s', $this->mediaType(), base64_encode((string) $this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show debug info for the current image
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function __debugInfo(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'mimetype' => $this->mimetype(),
|
||||||
|
'size' => $this->size(),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -364,4 +364,17 @@ class Rectangle extends Polygon implements SizeInterface
|
|||||||
{
|
{
|
||||||
return new RectangleResizer($width, $height);
|
return new RectangleResizer($width, $height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show debug info for the current rectangle
|
||||||
|
*
|
||||||
|
* @return array<string, int>
|
||||||
|
*/
|
||||||
|
public function __debugInfo(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'width' => $this->width(),
|
||||||
|
'height' => $this->height(),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -882,7 +882,7 @@ final class Image implements ImageInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* @see ImageInterface::drawBezier()
|
* @see ImageInterface::drawBezier()
|
||||||
@@ -1065,6 +1065,23 @@ final class Image implements ImageInterface
|
|||||||
return $this->encode(new HeicEncoder(...$options));
|
return $this->encode(new HeicEncoder(...$options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show debug info for the current image
|
||||||
|
*
|
||||||
|
* @return array<string, int>
|
||||||
|
*/
|
||||||
|
public function __debugInfo(): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return [
|
||||||
|
'width' => $this->width(),
|
||||||
|
'height' => $this->height(),
|
||||||
|
];
|
||||||
|
} catch (RuntimeException) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone image
|
* Clone image
|
||||||
*
|
*
|
||||||
|
@@ -115,4 +115,13 @@ final class ColorTest extends BaseTestCase
|
|||||||
$color = new Color(0, 0, 0, 0);
|
$color = new Color(0, 0, 0, 0);
|
||||||
$this->assertFalse($color->isClear());
|
$this->assertFalse($color->isClear());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = (new Color(10, 20, 30, 40))->__debugInfo();
|
||||||
|
$this->assertEquals(10, $info['cyan']);
|
||||||
|
$this->assertEquals(20, $info['magenta']);
|
||||||
|
$this->assertEquals(30, $info['yellow']);
|
||||||
|
$this->assertEquals(40, $info['key']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -114,4 +114,12 @@ final class ColorTest extends BaseTestCase
|
|||||||
$color = new Color(0, 1, 0);
|
$color = new Color(0, 1, 0);
|
||||||
$this->assertFalse($color->isClear());
|
$this->assertFalse($color->isClear());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = (new Color(10, 20, 30))->__debugInfo();
|
||||||
|
$this->assertEquals(10, $info['hue']);
|
||||||
|
$this->assertEquals(20, $info['saturation']);
|
||||||
|
$this->assertEquals(30, $info['luminance']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -114,4 +114,12 @@ final class ColorTest extends BaseTestCase
|
|||||||
$color = new Color(0, 1, 0);
|
$color = new Color(0, 1, 0);
|
||||||
$this->assertFalse($color->isClear());
|
$this->assertFalse($color->isClear());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = (new Color(10, 20, 30))->__debugInfo();
|
||||||
|
$this->assertEquals(10, $info['hue']);
|
||||||
|
$this->assertEquals(20, $info['saturation']);
|
||||||
|
$this->assertEquals(30, $info['value']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -176,4 +176,13 @@ final class ColorTest extends BaseTestCase
|
|||||||
$color = new Color(255, 255, 255, 0);
|
$color = new Color(255, 255, 255, 0);
|
||||||
$this->assertTrue($color->isClear());
|
$this->assertTrue($color->isClear());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = (new Color(10, 20, 30, 40))->__debugInfo();
|
||||||
|
$this->assertEquals(10, $info['red']);
|
||||||
|
$this->assertEquals(20, $info['green']);
|
||||||
|
$this->assertEquals(30, $info['blue']);
|
||||||
|
$this->assertEquals(40, $info['alpha']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -108,4 +108,13 @@ final class FrameTest extends BaseTestCase
|
|||||||
$frame = $this->getTestFrame();
|
$frame = $this->getTestFrame();
|
||||||
$this->assertInstanceOf(Image::class, $frame->toImage(new Driver()));
|
$this->assertInstanceOf(Image::class, $frame->toImage(new Driver()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = $this->getTestFrame()->__debugInfo();
|
||||||
|
$this->assertEquals(0, $info['delay']);
|
||||||
|
$this->assertEquals(0, $info['left']);
|
||||||
|
$this->assertEquals(0, $info['top']);
|
||||||
|
$this->assertEquals(1, $info['dispose']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -390,4 +390,11 @@ final class ImageTest extends GdTestCase
|
|||||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||||
$this->assertEquals('4cfaff', $image->pickColor(14, 14)->toHex());
|
$this->assertEquals('4cfaff', $image->pickColor(14, 14)->toHex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = $this->readTestImage('trim.png')->__debugInfo();
|
||||||
|
$this->assertArrayHasKey('width', $info);
|
||||||
|
$this->assertArrayHasKey('height', $info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -392,4 +392,11 @@ final class ImageTest extends ImagickTestCase
|
|||||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||||
$this->assertEquals('39c9ff', $image->pickColor(14, 14)->toHex());
|
$this->assertEquals('39c9ff', $image->pickColor(14, 14)->toHex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = $this->readTestImage('trim.png')->__debugInfo();
|
||||||
|
$this->assertArrayHasKey('width', $info);
|
||||||
|
$this->assertArrayHasKey('height', $info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,4 +57,11 @@ final class EncodedImageTest extends BaseTestCase
|
|||||||
$image = new EncodedImage($this->getTestResourceData(), 'image/jpeg');
|
$image = new EncodedImage($this->getTestResourceData(), 'image/jpeg');
|
||||||
$this->assertEquals('image/jpeg', $image->mimetype());
|
$this->assertEquals('image/jpeg', $image->mimetype());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = (new EncodedImage('foo', 'image/png'))->__debugInfo();
|
||||||
|
$this->assertEquals('image/png', $info['mimetype']);
|
||||||
|
$this->assertEquals(3, $info['size']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -325,4 +325,11 @@ final class RectangleTest extends BaseTestCase
|
|||||||
$this->assertEquals(800, $result->width());
|
$this->assertEquals(800, $result->width());
|
||||||
$this->assertEquals(600, $result->height());
|
$this->assertEquals(600, $result->height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDebugInfo(): void
|
||||||
|
{
|
||||||
|
$info = (new Rectangle(800, 600))->__debugInfo();
|
||||||
|
$this->assertEquals(800, $info['width']);
|
||||||
|
$this->assertEquals(600, $info['height']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user