mirror of
https://github.com/Intervention/image.git
synced 2025-08-21 21:15:11 +02:00
Refine color profiles
- Add tests for profile methods - Add ProfileInterface - Add profile methods to ImageInterface
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
namespace Intervention\Image\Colors;
|
||||
|
||||
use Intervention\Image\GenericData;
|
||||
use Intervention\Image\Interfaces\ProfileInterface;
|
||||
|
||||
class Profile extends GenericData
|
||||
class Profile extends GenericData implements ProfileInterface
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
use Intervention\Image\Interfaces\FrameInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ProfileInterface;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
@@ -83,6 +84,11 @@ class Image extends AbstractImage implements ImageInterface, IteratorAggregate
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ImageInterface::getColorspace()
|
||||
*/
|
||||
public function getColorspace(): ColorspaceInterface
|
||||
{
|
||||
return new RgbColorspace();
|
||||
@@ -105,4 +111,34 @@ class Image extends AbstractImage implements ImageInterface, IteratorAggregate
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ImageInterface::setProfile()
|
||||
*/
|
||||
public function setProfile(string|ProfileInterface $input): ImageInterface
|
||||
{
|
||||
throw new NotSupportedException('Color profiles are not supported by GD driver.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ImageInterface::profile()
|
||||
*/
|
||||
public function profile(): ProfileInterface
|
||||
{
|
||||
throw new NotSupportedException('Color profiles are not supported by GD driver.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ImageInterface::withoutProfile()
|
||||
*/
|
||||
public function withoutProfile(): ImageInterface
|
||||
{
|
||||
throw new NotSupportedException('Color profiles are not supported by GD driver.');
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
use Intervention\Image\Interfaces\FrameInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ProfileInterface;
|
||||
use Iterator;
|
||||
|
||||
class Image extends AbstractImage implements ImageInterface, Iterator
|
||||
@@ -162,16 +163,24 @@ class Image extends AbstractImage implements ImageInterface, Iterator
|
||||
return $this->modify(new ColorspaceModifier($colorspace));
|
||||
}
|
||||
|
||||
public function setProfile(string $filepath): ImageInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ImageInterface::setProfile()
|
||||
*/
|
||||
public function setProfile(string|ProfileInterface $input): ImageInterface
|
||||
{
|
||||
return $this->modify(
|
||||
new ProfileModifier(
|
||||
new Profile(file_get_contents($filepath))
|
||||
)
|
||||
);
|
||||
$profile = is_object($input) ? $input : new Profile(file_get_contents($input));
|
||||
|
||||
return $this->modify(new ProfileModifier($profile));
|
||||
}
|
||||
|
||||
public function getProfile(): Profile
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ImageInterface::profile()
|
||||
*/
|
||||
public function profile(): ProfileInterface
|
||||
{
|
||||
$profiles = $this->imagick->getImageProfiles('icc');
|
||||
|
||||
@@ -182,6 +191,11 @@ class Image extends AbstractImage implements ImageInterface, Iterator
|
||||
return new Profile($profiles['icc']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see ImageInterface::withoutProfile()
|
||||
*/
|
||||
public function withoutProfile(): ImageInterface
|
||||
{
|
||||
return $this->modify(new ProfileRemovalModifier());
|
||||
|
@@ -155,6 +155,28 @@ interface ImageInterface extends Traversable, Countable
|
||||
*/
|
||||
public function setColorspace(string|ColorspaceInterface $target): ImageInterface;
|
||||
|
||||
/**
|
||||
* Retrieve ICC color profile of image
|
||||
*
|
||||
* @return ProfileInterface
|
||||
*/
|
||||
public function profile(): ProfileInterface;
|
||||
|
||||
/**
|
||||
* Set ICC color profile on the current image
|
||||
*
|
||||
* @param string|ProfileInterface $input Path to color profile or profile object
|
||||
* @return ImageInterface
|
||||
*/
|
||||
public function setProfile(string|ProfileInterface $input): ImageInterface;
|
||||
|
||||
/**
|
||||
* Remove ICC color profile from the current image
|
||||
*
|
||||
* @return ImageInterface
|
||||
*/
|
||||
public function withoutProfile(): ImageInterface;
|
||||
|
||||
/**
|
||||
* Draw text on image
|
||||
*
|
||||
|
8
src/Interfaces/ProfileInterface.php
Normal file
8
src/Interfaces/ProfileInterface.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Interfaces;
|
||||
|
||||
interface ProfileInterface
|
||||
{
|
||||
public function __toString(): string;
|
||||
}
|
@@ -6,8 +6,10 @@ use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
|
||||
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
|
||||
use Intervention\Image\Colors\Profile;
|
||||
use Intervention\Image\Drivers\Imagick\Frame;
|
||||
use Intervention\Image\Drivers\Imagick\Image;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Geometry\Rectangle;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
@@ -129,4 +131,26 @@ class ImageTest extends TestCase
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(CmykColorspace::class, $result->getColorspace());
|
||||
}
|
||||
|
||||
public function testSetGetProfile(): void
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImageBlob($this->getTestImageData('test.jpg'));
|
||||
$image = new Image($imagick);
|
||||
$result = $image->profile();
|
||||
$this->assertInstanceOf(Profile::class, $result);
|
||||
$result = $image->setProfile($result);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testWithoutProfile(): void
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImageBlob($this->getTestImageData('test.jpg'));
|
||||
$image = new Image($imagick);
|
||||
$result = $image->withoutProfile();
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->expectException(ColorException::class);
|
||||
$image->profile();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user