repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/EncodedImageTest.php
tests/Unit/EncodedImageTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\EncodedImage; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(EncodedImage::class)] final class EncodedImageTest extends BaseTestCase { public function testConstructor(): void { $image = new EncodedImage('foo'); $this->assertInstanceOf(EncodedImage::class, $image); } public function testSave(): void { $image = new EncodedImage('foo'); $path = __DIR__ . '/foo.tmp'; $this->assertFalse(file_exists($path)); $image->save($path); $this->assertTrue(file_exists($path)); $this->assertEquals('foo', file_get_contents($path)); unlink($path); } public function testToDataUri(): void { $image = new EncodedImage('foo'); $this->assertEquals('data:application/octet-stream;base64,Zm9v', $image->toDataUri()); } public function testToString(): void { $image = new EncodedImage('foo'); $this->assertEquals('foo', (string) $image); } public function testMediaType(): void { $image = new EncodedImage('foo'); $this->assertEquals('application/octet-stream', $image->mediaType()); $image = new EncodedImage($this->getTestResourceData(), 'image/jpeg'); $this->assertEquals('image/jpeg', $image->mediaType()); } public function testMimetype(): void { $image = new EncodedImage('foo'); $this->assertEquals('application/octet-stream', $image->mimetype()); $image = new EncodedImage($this->getTestResourceData(), 'image/jpeg'); $this->assertEquals('image/jpeg', $image->mimetype()); } public function testDebugInfo(): void { $info = (new EncodedImage('foo', 'image/png'))->__debugInfo(); $this->assertEquals('image/png', $info['mediaType']); $this->assertEquals(3, $info['size']); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/ImageManagerTestGd.php
tests/Unit/ImageManagerTestGd.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Decoders\BinaryImageDecoder; use Intervention\Image\Decoders\FilePathImageDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(ImageManager::class)] #[RequiresPhpExtension('gd')] final class ImageManagerTestGd extends BaseTestCase { public function testConstructor(): void { $manager = new ImageManager(new Driver()); $this->assertInstanceOf(ImageManager::class, $manager); $manager = new ImageManager(Driver::class); $this->assertInstanceOf(ImageManager::class, $manager); } public function testWithDriver(): void { $manager = ImageManager::withDriver(new Driver()); $this->assertInstanceOf(ImageManager::class, $manager); $manager = ImageManager::withDriver(Driver::class); $this->assertInstanceOf(ImageManager::class, $manager); } public function testDriver(): void { $driver = new Driver(); $manager = ImageManager::withDriver($driver); $this->assertEquals($driver, $manager->driver()); } public function testDriverStatic(): void { $manager = ImageManager::gd(); $this->assertInstanceOf(ImageManager::class, $manager); } public function testCreate(): void { $manager = new ImageManager(Driver::class); $image = $manager->create(5, 4); $this->assertInstanceOf(ImageInterface::class, $image); } public function testAnimate(): void { $manager = new ImageManager(Driver::class); $image = $manager->animate(function ($animation): void { $animation->add($this->getTestResourcePath('red.gif'), .25); }); $this->assertInstanceOf(ImageInterface::class, $image); } public function testRead(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('red.gif')); $this->assertInstanceOf(ImageInterface::class, $image); } public function testReadWithDecoderClassname(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('red.gif'), FilePathImageDecoder::class); $this->assertInstanceOf(ImageInterface::class, $image); } public function testReadWithDecoderInstance(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('red.gif'), new FilePathImageDecoder()); $this->assertInstanceOf(ImageInterface::class, $image); } public function testReadWithDecoderClassnameArray(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('red.gif'), [FilePathImageDecoder::class]); $this->assertInstanceOf(ImageInterface::class, $image); } public function testReadWithDecoderInstanceArray(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('red.gif'), [new FilePathImageDecoder()]); $this->assertInstanceOf(ImageInterface::class, $image); } public function testReadWithDecoderInstanceArrayMultiple(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('red.gif'), [ new BinaryImageDecoder(), new FilePathImageDecoder(), ]); $this->assertInstanceOf(ImageInterface::class, $image); } public function testReadWithRotationAdjustment(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('orientation.jpg')); $this->assertColor(1, 0, 254, 255, $image->pickColor(3, 3)); } public function testReadWithoutRotationAdjustment(): void { $manager = new ImageManager(Driver::class, autoOrientation: false); $image = $manager->read($this->getTestResourcePath('orientation.jpg')); $this->assertColor(250, 2, 3, 255, $image->pickColor(3, 3)); } public function testReadAnimation(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('animation.gif')); $this->assertTrue($image->isAnimated()); } public function testReadAnimationDiscarded(): void { $manager = new ImageManager(Driver::class, decodeAnimation: false); $image = $manager->read($this->getTestResourcePath('animation.gif')); $this->assertFalse($image->isAnimated()); } public function testApplyBlendingColorDefault(): void { $manager = new ImageManager(Driver::class); $image = $manager->read($this->getTestResourcePath('blocks.png')); $result = $image->blendTransparency(); $this->assertColor(255, 255, 255, 255, $image->pickColor(530, 0)); $this->assertColor(255, 255, 255, 255, $result->pickColor(530, 0)); } public function testApplyBlendingColorConfigured(): void { $manager = new ImageManager(Driver::class, blendingColor: 'ff5500'); $image = $manager->read($this->getTestResourcePath('blocks.png')); $result = $image->blendTransparency(); $this->assertColor(255, 85, 0, 255, $image->pickColor(530, 0)); $this->assertColor(255, 85, 0, 255, $result->pickColor(530, 0)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/ConfigTest.php
tests/Unit/ConfigTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit; use Intervention\Image\Config; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Config::class)] final class ConfigTest extends BaseTestCase { public function testConstructor(): void { $config = new Config(); $this->assertInstanceOf(Config::class, $config); $this->assertTrue($config->autoOrientation); $this->assertTrue($config->decodeAnimation); $this->assertEquals('ffffff', $config->blendingColor); $config = new Config( autoOrientation: false, decodeAnimation: false, blendingColor: 'f00', strip: true, ); $this->assertInstanceOf(Config::class, $config); $this->assertFalse($config->autoOrientation); $this->assertFalse($config->decodeAnimation); $this->assertTrue($config->strip); $this->assertEquals('f00', $config->blendingColor); } public function testGetSetOptions(): void { $config = new Config(); $this->assertTrue($config->autoOrientation); $this->assertTrue($config->decodeAnimation); $this->assertFalse($config->strip); $this->assertEquals('ffffff', $config->blendingColor); $result = $config->setOptions( autoOrientation: false, decodeAnimation: false, blendingColor: 'f00', strip: true, ); $this->assertFalse($config->autoOrientation); $this->assertFalse($config->decodeAnimation); $this->assertEquals('f00', $config->blendingColor); $this->assertFalse($result->autoOrientation); $this->assertFalse($result->decodeAnimation); $this->assertTrue($result->strip); $this->assertEquals('f00', $result->blendingColor); $result = $config->setOptions(blendingColor: '000'); $this->assertFalse($config->autoOrientation); $this->assertFalse($config->decodeAnimation); $this->assertTrue($config->strip); $this->assertEquals('000', $config->blendingColor); $this->assertFalse($result->autoOrientation); $this->assertFalse($result->decodeAnimation); $this->assertTrue($result->strip); $this->assertEquals('000', $result->blendingColor); } public function testSetOptionsWithArray(): void { $config = new Config(); $result = $config->setOptions([ 'autoOrientation' => false, 'decodeAnimation' => false, 'blendingColor' => 'f00', 'strip' => true, ]); $this->assertFalse($config->autoOrientation); $this->assertFalse($config->decodeAnimation); $this->assertTrue($config->strip); $this->assertEquals('f00', $config->blendingColor); $this->assertFalse($result->autoOrientation); $this->assertFalse($result->decodeAnimation); $this->assertTrue($result->strip); $this->assertEquals('f00', $result->blendingColor); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/ResolutionTest.php
tests/Unit/ResolutionTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Resolution; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Resolution::class)] final class ResolutionTest extends BaseTestCase { public function testConstructor(): void { $resolution = new Resolution(1, 2); $this->assertInstanceOf(Resolution::class, $resolution); } public function testIteration(): void { $resolution = new Resolution(1.2, 3.4); foreach ($resolution as $value) { $this->assertIsFloat($value); } } public function testXY(): void { $resolution = new Resolution(1.2, 3.4); $this->assertEquals(1.2, $resolution->x()); $this->assertEquals(3.4, $resolution->y()); } public function testUnit(): void { $resolution = new Resolution(1, 1); $this->assertEquals('dpi', $resolution->unit()); $resolution = new Resolution(1, 1, Resolution::PER_CM); $this->assertEquals('dpcm', $resolution->unit()); } public function testConversion(): void { $resolution = new Resolution(300, 150); // per inch $this->assertEquals(300, $resolution->perInch()->x()); $this->assertEquals(150, $resolution->perInch()->y()); $resolution = new Resolution(300, 150); // per inch $this->assertEquals(118.11, round($resolution->perCm()->x(), 2)); $this->assertEquals(59.06, round($resolution->perCm()->y(), 2)); $resolution = new Resolution(118.11024, 59.06, Resolution::PER_CM); // per cm $this->assertEquals(300, round($resolution->perInch()->x())); $this->assertEquals(150, round($resolution->perInch()->y())); } public function testToString(): void { $resolution = new Resolution(300, 150, Resolution::PER_CM); $this->assertEquals('300.00 x 150.00 dpcm', $resolution->toString()); $resolution = new Resolution(300, 150, Resolution::PER_INCH); $this->assertEquals('300.00 x 150.00 dpi', $resolution->toString()); $this->assertEquals('300.00 x 150.00 dpi', (string) $resolution); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/FormatTest.php
tests/Unit/FormatTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit; use Intervention\Image\Encoders\AvifEncoder; use Intervention\Image\Encoders\BmpEncoder; use Intervention\Image\Encoders\GifEncoder; use Intervention\Image\Encoders\HeicEncoder; use Intervention\Image\Encoders\Jpeg2000Encoder; use Intervention\Image\Encoders\JpegEncoder; use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Encoders\TiffEncoder; use Intervention\Image\Encoders\WebpEncoder; use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\FileExtension; use Intervention\Image\Format; use Intervention\Image\MediaType; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Format::class)] final class FormatTest extends BaseTestCase { public function testCreate(): void { $this->assertEquals(Format::JPEG, Format::create(Format::JPEG)); $this->assertEquals(Format::JPEG, Format::create('jpg')); $this->assertEquals(Format::JPEG, Format::create('jpeg')); $this->assertEquals(Format::JPEG, Format::create('image/jpeg')); $this->assertEquals(Format::GIF, Format::create('image/gif')); $this->assertEquals(Format::JPEG, Format::create('JPG')); $this->assertEquals(Format::JPEG, Format::create('JPEG')); $this->assertEquals(Format::JPEG, Format::create('IMAGE/JPEG')); $this->assertEquals(Format::GIF, Format::create('IMAGE/GIF')); $this->assertEquals(Format::PNG, Format::create(FileExtension::PNG)); $this->assertEquals(Format::WEBP, Format::create(MediaType::IMAGE_WEBP)); } public function testCreateUnknown(): void { $this->expectException(NotSupportedException::class); Format::create('foo'); } public function testTryCreate(): void { $this->assertEquals(Format::JPEG, Format::tryCreate(Format::JPEG)); $this->assertEquals(Format::JPEG, Format::tryCreate('jpg')); $this->assertEquals(Format::JPEG, Format::tryCreate('jpeg')); $this->assertEquals(Format::JPEG, Format::tryCreate('image/jpeg')); $this->assertEquals(Format::GIF, Format::tryCreate('image/gif')); $this->assertEquals(Format::PNG, Format::tryCreate(FileExtension::PNG)); $this->assertEquals(Format::WEBP, Format::tryCreate(MediaType::IMAGE_WEBP)); $this->assertNull(Format::tryCreate('no-format')); } public function testMediaTypesJpeg(): void { $format = Format::JPEG; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(4, $mediaTypes); $this->assertEquals(MediaType::IMAGE_JPEG, $format->mediaType()); } public function testMediaTypesWebp(): void { $format = Format::WEBP; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(2, $mediaTypes); $this->assertEquals(MediaType::IMAGE_WEBP, $format->mediaType()); } public function testMediaTypesFGif(): void { $format = Format::GIF; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(1, $mediaTypes); $this->assertEquals(MediaType::IMAGE_GIF, $format->mediaType()); } public function testMediaTypesPng(): void { $format = Format::PNG; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(2, $mediaTypes); $this->assertEquals(MediaType::IMAGE_PNG, $format->mediaType()); } public function testMediaTypesAvif(): void { $format = Format::AVIF; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(2, $mediaTypes); $this->assertEquals(MediaType::IMAGE_AVIF, $format->mediaType()); } public function testMediaTypesBmp(): void { $format = Format::BMP; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(9, $mediaTypes); $this->assertEquals(MediaType::IMAGE_BMP, $format->mediaType()); } public function testMediaTypesTiff(): void { $format = Format::TIFF; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(1, $mediaTypes); $this->assertEquals(MediaType::IMAGE_TIFF, $format->mediaType()); } public function testMediaTypesJpeg2000(): void { $format = Format::JP2; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(4, $mediaTypes); $this->assertEquals(MediaType::IMAGE_JP2, $format->mediaType()); } public function testMediaTypesHeic(): void { $format = Format::HEIC; $mediaTypes = $format->mediaTypes(); $this->assertIsArray($mediaTypes); $this->assertCount(3, $mediaTypes); $this->assertEquals(MediaType::IMAGE_HEIC, $format->mediaType()); } public function testEncoderJpeg(): void { $format = Format::JPEG; $this->assertInstanceOf(JpegEncoder::class, $format->encoder()); } public function testEncoderAvif(): void { $format = Format::AVIF; $this->assertInstanceOf(AvifEncoder::class, $format->encoder()); } public function testEncoderWebp(): void { $format = Format::WEBP; $this->assertInstanceOf(WebpEncoder::class, $format->encoder()); } public function testEncoderGif(): void { $format = Format::GIF; $this->assertInstanceOf(GifEncoder::class, $format->encoder()); } public function testEncoderPng(): void { $format = Format::PNG; $this->assertInstanceOf(PngEncoder::class, $format->encoder()); } public function testEncoderBitmap(): void { $format = Format::BMP; $this->assertInstanceOf(BmpEncoder::class, $format->encoder()); } public function testEncoderTiff(): void { $format = Format::TIFF; $this->assertInstanceOf(TiffEncoder::class, $format->encoder()); } public function testEncoderJpep2000(): void { $format = Format::JP2; $this->assertInstanceOf(Jpeg2000Encoder::class, $format->encoder()); } public function testEncoderHeic(): void { $format = Format::HEIC; $this->assertInstanceOf(HeicEncoder::class, $format->encoder()); } public function testFileExtensionsJpeg(): void { $format = Format::JPEG; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(2, $extensions); $this->assertEquals(FileExtension::JPG, $format->fileExtension()); } public function testFileExtensionsWebp(): void { $format = Format::WEBP; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(1, $extensions); $this->assertEquals(FileExtension::WEBP, $format->fileExtension()); } public function testFileExtensionsGif(): void { $format = Format::GIF; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(1, $extensions); $this->assertEquals(FileExtension::GIF, $format->fileExtension()); } public function testFileExtensionsPng(): void { $format = Format::PNG; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(1, $extensions); $this->assertEquals(FileExtension::PNG, $format->fileExtension()); } public function testFileExtensionsAvif(): void { $format = Format::AVIF; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(1, $extensions); $this->assertEquals(FileExtension::AVIF, $format->fileExtension()); } public function testFileExtensionsBmp(): void { $format = Format::BMP; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(1, $extensions); $this->assertEquals(FileExtension::BMP, $format->fileExtension()); } public function testFileExtensionsTiff(): void { $format = Format::TIFF; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(2, $extensions); $this->assertEquals(FileExtension::TIF, $format->fileExtension()); } public function testFileExtensionsJp2(): void { $format = Format::JP2; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(9, $extensions); $this->assertEquals(FileExtension::JP2, $format->fileExtension()); } public function testFileExtensionsHeic(): void { $format = Format::HEIC; $extensions = $format->fileExtensions(); $this->assertIsArray($extensions); $this->assertCount(2, $extensions); $this->assertEquals(FileExtension::HEIC, $format->fileExtension()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Encoders/MediaTypeEncoderTest.php
tests/Unit/Encoders/MediaTypeEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Encoders; use Generator; use Intervention\Image\Encoders\AvifEncoder; use Intervention\Image\Encoders\BmpEncoder; use Intervention\Image\Encoders\GifEncoder; use Intervention\Image\Encoders\HeicEncoder; use Intervention\Image\Encoders\Jpeg2000Encoder; use Intervention\Image\Encoders\JpegEncoder; use Intervention\Image\Encoders\MediaTypeEncoder; use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Encoders\TiffEncoder; use Intervention\Image\Encoders\WebpEncoder; use Intervention\Image\Exceptions\EncoderException; use Intervention\Image\Interfaces\EncoderInterface; use Intervention\Image\MediaType; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(MediaTypeEncoder::class)] final class MediaTypeEncoderTest extends BaseTestCase { /** * @param $options array<string, int> */ private function testEncoder(string|MediaType $mediaType, array $options = []): EncoderInterface { $encoder = new class ($mediaType, ...$options) extends MediaTypeEncoder { public function __construct(string|MediaType $mediaType, mixed ...$options) { parent::__construct($mediaType, ...$options); } public function test(string|MediaType $mediaType): EncoderInterface { return $this->encoderByMediaType($mediaType); } }; return $encoder->test($mediaType); } #[DataProvider('targetEncoderProvider')] public function testEncoderByMediaType( string|MediaType $mediaType, string $targetEncoderClassname, ): void { $this->assertInstanceOf( $targetEncoderClassname, $this->testEncoder($mediaType) ); } public static function targetEncoderProvider(): Generator { yield ['image/webp', WebpEncoder::class]; yield ['image/avif', AvifEncoder::class]; yield ['image/jpeg', JpegEncoder::class]; yield ['image/bmp', BmpEncoder::class]; yield ['image/gif', GifEncoder::class]; yield ['image/png', PngEncoder::class]; yield ['image/png', PngEncoder::class]; yield ['image/tiff', TiffEncoder::class]; yield ['image/jp2', Jpeg2000Encoder::class]; yield ['image/heic', HeicEncoder::class]; yield [MediaType::IMAGE_WEBP, WebpEncoder::class]; yield [MediaType::IMAGE_AVIF, AvifEncoder::class]; yield [MediaType::IMAGE_JPEG, JpegEncoder::class]; yield [MediaType::IMAGE_BMP, BmpEncoder::class]; yield [MediaType::IMAGE_GIF, GifEncoder::class]; yield [MediaType::IMAGE_PNG, PngEncoder::class]; yield [MediaType::IMAGE_TIFF, TiffEncoder::class]; yield [MediaType::IMAGE_JP2, Jpeg2000Encoder::class]; yield [MediaType::IMAGE_HEIC, HeicEncoder::class]; yield [MediaType::IMAGE_HEIF, HeicEncoder::class]; } public function testArgumentsNotSupportedByTargetEncoder(): void { $encoder = $this->testEncoder( 'image/png', [ 'interlaced' => true, // is not ignored 'quality' => 10, // is ignored because png encoder has no quality argument ], ); $this->assertInstanceOf(PngEncoder::class, $encoder); $this->assertTrue($encoder->interlaced); } public function testEncoderByFileExtensionUnknown(): void { $this->expectException(EncoderException::class); $this->testEncoder('test'); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Encoders/FileExtensionEncoderTest.php
tests/Unit/Encoders/FileExtensionEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Encoders; use Generator; use Intervention\Image\Encoders\AvifEncoder; use Intervention\Image\Encoders\BmpEncoder; use Intervention\Image\Encoders\FileExtensionEncoder; use Intervention\Image\Encoders\GifEncoder; use Intervention\Image\Encoders\HeicEncoder; use Intervention\Image\Encoders\Jpeg2000Encoder; use Intervention\Image\Encoders\JpegEncoder; use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Encoders\TiffEncoder; use Intervention\Image\Encoders\WebpEncoder; use Intervention\Image\Exceptions\EncoderException; use Intervention\Image\FileExtension; use Intervention\Image\Interfaces\EncoderInterface; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(FileExtensionEncoder::class)] final class FileExtensionEncoderTest extends BaseTestCase { /** * @param $options array<string, int> */ private function testEncoder(string|FileExtension $extension, array $options = []): EncoderInterface { $encoder = new class ($extension, ...$options) extends FileExtensionEncoder { public function __construct(string|FileExtension $extension, mixed ...$options) { parent::__construct($extension, ...$options); } public function test(string|FileExtension $extension): EncoderInterface { return $this->encoderByFileExtension($extension); } }; return $encoder->test($extension); } #[DataProvider('targetEncoderProvider')] public function testEncoderByFileExtensionString( string|FileExtension $fileExtension, string $targetEncoderClassname, ): void { $this->assertInstanceOf( $targetEncoderClassname, $this->testEncoder($fileExtension), ); } public static function targetEncoderProvider(): Generator { yield ['webp', WebpEncoder::class]; yield ['avif', AvifEncoder::class]; yield ['jpeg', JpegEncoder::class]; yield ['jpg', JpegEncoder::class]; yield ['bmp', BmpEncoder::class]; yield ['gif', GifEncoder::class]; yield ['png', PngEncoder::class]; yield ['tiff', TiffEncoder::class]; yield ['tif', TiffEncoder::class]; yield ['jp2', Jpeg2000Encoder::class]; yield ['heic', HeicEncoder::class]; yield ['WEBP', WebpEncoder::class]; yield ['AVIF', AvifEncoder::class]; yield ['JPEG', JpegEncoder::class]; yield ['JPG', JpegEncoder::class]; yield ['BMP', BmpEncoder::class]; yield ['GIF', GifEncoder::class]; yield ['PNG', PngEncoder::class]; yield ['TIFF', TiffEncoder::class]; yield ['TIF', TiffEncoder::class]; yield ['JP2', Jpeg2000Encoder::class]; yield ['HEIC', HeicEncoder::class]; yield [FileExtension::WEBP, WebpEncoder::class]; yield [FileExtension::AVIF, AvifEncoder::class]; yield [FileExtension::JPG, JpegEncoder::class]; yield [FileExtension::BMP, BmpEncoder::class]; yield [FileExtension::GIF, GifEncoder::class]; yield [FileExtension::PNG, PngEncoder::class]; yield [FileExtension::TIF, TiffEncoder::class]; yield [FileExtension::TIFF, TiffEncoder::class]; yield [FileExtension::JP2, Jpeg2000Encoder::class]; yield [FileExtension::HEIC, HeicEncoder::class]; } public function testArgumentsNotSupportedByTargetEncoder(): void { $encoder = $this->testEncoder( 'png', [ 'interlaced' => true, // is not ignored 'quality' => 10, // is ignored because png encoder has no quality argument ], ); $this->assertInstanceOf(PngEncoder::class, $encoder); $this->assertTrue($encoder->interlaced); } public function testEncoderByFileExtensionUnknown(): void { $this->expectException(EncoderException::class); $this->testEncoder('test'); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/ProfileTest.php
tests/Unit/Colors/ProfileTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors; use Intervention\Image\Colors\Profile; use Intervention\Image\Tests\BaseTestCase; class ProfileTest extends BaseTestCase { public function testFromPath(): void { $profile = Profile::fromPath($this->getTestResourcePath()); $this->assertInstanceOf(Profile::class, $profile); $this->assertTrue($profile->size() > 0); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsv/ColorTest.php
tests/Unit/Colors/Hsv/ColorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsv; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Hsv\Channels\Hue; use Intervention\Image\Colors\Hsv\Channels\Saturation; use Intervention\Image\Colors\Hsv\Channels\Value; use Intervention\Image\Colors\Hsv\Color; use Intervention\Image\Colors\Hsv\Colorspace; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Color::class)] final class ColorTest extends BaseTestCase { public function testConstructor(): void { $color = new Color(0, 0, 0); $this->assertInstanceOf(Color::class, $color); } public function testCreate(): void { $color = Color::create('hsv(10, 20, 30)'); $this->assertInstanceOf(Color::class, $color); } public function testColorspace(): void { $color = new Color(0, 0, 0); $this->assertInstanceOf(Colorspace::class, $color->colorspace()); } public function testChannels(): void { $color = new Color(10, 20, 30); $this->assertIsArray($color->channels()); $this->assertCount(3, $color->channels()); } public function testChannel(): void { $color = new Color(10, 20, 30); $channel = $color->channel(Hue::class); $this->assertInstanceOf(Hue::class, $channel); $this->assertEquals(10, $channel->value()); } public function testChannelNotFound(): void { $color = new Color(10, 20, 30); $this->expectException(ColorException::class); $color->channel('none'); } public function testHueSaturationValueKey(): void { $color = new Color(10, 20, 30); $this->assertInstanceOf(Hue::class, $color->hue()); $this->assertInstanceOf(Saturation::class, $color->saturation()); $this->assertInstanceOf(Value::class, $color->value()); $this->assertEquals(10, $color->hue()->value()); $this->assertEquals(20, $color->saturation()->value()); $this->assertEquals(30, $color->value()->value()); } public function testToArray(): void { $color = new Color(10, 20, 30); $this->assertEquals([10, 20, 30], $color->toArray()); } public function testToHex(): void { $color = new Color(16, 100, 100); $this->assertEquals('ff4400', $color->toHex()); } public function testNormalize(): void { $color = new Color(180, 50, 25); $this->assertEquals([.5, 0.5, 0.25], $color->normalize()); } public function testToString(): void { $color = new Color(100, 50, 20, 0); $this->assertEquals('hsv(100, 50%, 20%)', (string) $color); } public function testIsGreyscale(): void { $color = new Color(0, 1, 0); $this->assertFalse($color->isGreyscale()); $color = new Color(1, 0, 0); $this->assertTrue($color->isGreyscale()); $color = new Color(0, 0, 1); $this->assertTrue($color->isGreyscale()); } public function testIsTransparent(): void { $color = new Color(1, 0, 0); $this->assertFalse($color->isTransparent()); } public function testIsClear(): void { $color = new Color(0, 1, 0); $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']); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsv/ChannelTest.php
tests/Unit/Colors/Hsv/ChannelTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsv; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Hsv\Channels\Hue; use Intervention\Image\Colors\Hsv\Channels\Saturation; use Intervention\Image\Colors\Hsv\Channels\Value; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Hue::class)] #[CoversClass(Saturation::class)] #[CoversClass(Value::class)] final class ChannelTest extends BaseTestCase { public function testConstructor(): void { $channel = new Hue(0); $this->assertInstanceOf(Hue::class, $channel); $channel = new Hue(value: 0); $this->assertInstanceOf(Hue::class, $channel); $channel = new Hue(normalized: 0); $this->assertInstanceOf(Hue::class, $channel); $this->expectException(ColorException::class); new Hue(); $this->expectException(ColorException::class); new Hue(normalized: 2); } public function testConstructorFail(): void { $this->expectException(ColorException::class); new Hue(400); } public function testToInt(): void { $channel = new Hue(10); $this->assertEquals(10, $channel->toInt()); } public function testToString(): void { $channel = new Hue(10); $this->assertEquals("10", $channel->toString()); $this->assertEquals("10", (string) $channel); } public function testValue(): void { $channel = new Hue(10); $this->assertEquals(10, $channel->value()); } public function testNormalize(): void { $channel = new Hue(360); $this->assertEquals(1, $channel->normalize()); $channel = new Hue(180); $this->assertEquals(0.5, $channel->normalize()); $channel = new Hue(0); $this->assertEquals(0, $channel->normalize()); $channel = new Hue(90); $this->assertEquals(.25, $channel->normalize()); } public function testValidate(): void { $this->expectException(ColorException::class); new Hue(361); $this->expectException(ColorException::class); new Hue(-1); $this->expectException(ColorException::class); new Saturation(101); $this->expectException(ColorException::class); new Saturation(-1); $this->expectException(ColorException::class); new Value(101); $this->expectException(ColorException::class); new Value(-1); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsv/ColorspaceTest.php
tests/Unit/Colors/Hsv/ColorspaceTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsv; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Hsv\Channels\Hue; use Intervention\Image\Colors\Hsv\Channels\Saturation; use Intervention\Image\Colors\Hsv\Channels\Value; use Intervention\Image\Colors\Hsv\Color as HsvColor; use Intervention\Image\Colors\Rgb\Color as RgbColor; use Intervention\Image\Colors\Hsl\Color as HslColor; use Intervention\Image\Colors\Hsv\Colorspace; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Colorspace::class)] final class ColorspaceTest extends BaseTestCase { public function testColorFromNormalized(): void { $colorspace = new Colorspace(); $result = $colorspace->colorFromNormalized([1, 0, 1]); $this->assertInstanceOf(HsvColor::class, $result); $this->assertEquals(360, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(100, $result->channel(Value::class)->value()); } public function testImportRgbColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new RgbColor(255, 0, 255)); $this->assertInstanceOf(HsvColor::class, $result); $this->assertEquals(300, $result->channel(Hue::class)->value()); $this->assertEquals(100, $result->channel(Saturation::class)->value()); $this->assertEquals(100, $result->channel(Value::class)->value()); $result = $colorspace->importColor(new RgbColor(127, 127, 127)); $this->assertInstanceOf(HsvColor::class, $result); $this->assertEquals(0, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Value::class)->value()); $result = $colorspace->importColor(new RgbColor(127, 127, 127, 85)); $this->assertInstanceOf(HsvColor::class, $result); $this->assertEquals(0, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Value::class)->value()); } public function testImportCmykColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new CmykColor(0, 100, 0, 0)); $this->assertInstanceOf(HsvColor::class, $result); $this->assertEquals(300, $result->channel(Hue::class)->value()); $this->assertEquals(100, $result->channel(Saturation::class)->value()); $this->assertEquals(100, $result->channel(Value::class)->value()); $result = $colorspace->importColor(new CmykColor(0, 0, 0, 50)); $this->assertInstanceOf(HsvColor::class, $result); $this->assertEquals(0, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Value::class)->value()); } public function testImportHslColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new HslColor(300, 100, 50)); $this->assertInstanceOf(HsvColor::class, $result); $this->assertEquals(300, $result->channel(Hue::class)->value()); $this->assertEquals(100, $result->channel(Saturation::class)->value()); $this->assertEquals(100, $result->channel(Value::class)->value()); $result = $colorspace->importColor(new HslColor(0, 0, 50)); $this->assertInstanceOf(HsvColor::class, $result); $this->assertEquals(0, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Value::class)->value()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsv/Channels/SaturationTest.php
tests/Unit/Colors/Hsv/Channels/SaturationTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsv\Channels; use Intervention\Image\Colors\Hsv\Channels\Saturation; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Saturation::class)] final class SaturationTest extends BaseTestCase { public function testMinMax(): void { $saturation = new Saturation(0); $this->assertEquals(0, $saturation->min()); $this->assertEquals(100, $saturation->max()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsv/Channels/ValueTest.php
tests/Unit/Colors/Hsv/Channels/ValueTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsv\Channels; use Intervention\Image\Colors\Hsv\Channels\Value; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Value::class)] final class ValueTest extends BaseTestCase { public function testMinMax(): void { $saturation = new Value(0); $this->assertEquals(0, $saturation->min()); $this->assertEquals(100, $saturation->max()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php
tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsv\Decoders; use Generator; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Hsv\Color; use Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(StringColorDecoder::class)] final class StringColorDecoderTest extends BaseTestCase { /** * @param $channelValues array<int> */ #[DataProvider('decodeDataProvier')] public function testDecodeHsv(string $input, string $classname, array $channelValues): void { $decoder = new StringColorDecoder(); $result = $decoder->decode($input); $this->assertInstanceOf($classname, $result); $this->assertEquals($channelValues, $result->toArray()); } public static function decodeDataProvier(): Generator { yield [ 'hsv(0,0,0)', Color::class, [0, 0, 0], ]; yield [ 'hsv(0, 100, 100)', Color::class, [0, 100, 100], ]; yield [ 'hsv(360, 100, 100)', Color::class, [360, 100, 100], ]; yield [ 'hsv(180, 100%, 100%)', Color::class, [180, 100, 100], ]; yield [ 'hsb(0,0,0)', Color::class, [0, 0, 0], ]; yield [ 'hsb(0, 100, 100)', Color::class, [0, 100, 100], ]; yield [ 'hsb(360, 100, 100)', Color::class, [360, 100, 100], ]; yield [ 'hsb(180, 100%, 100%)', Color::class, [180, 100, 100], ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsl/ColorTest.php
tests/Unit/Colors/Hsl/ColorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsl; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Hsl\Channels\Hue; use Intervention\Image\Colors\Hsl\Channels\Luminance; use Intervention\Image\Colors\Hsl\Channels\Saturation; use Intervention\Image\Colors\Hsl\Color; use Intervention\Image\Colors\Hsl\Colorspace; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Color::class)] final class ColorTest extends BaseTestCase { public function testConstructor(): void { $color = new Color(0, 0, 0); $this->assertInstanceOf(Color::class, $color); } public function testCreate(): void { $color = Color::create('hsl(10, 20, 30)'); $this->assertInstanceOf(Color::class, $color); } public function testColorspace(): void { $color = new Color(0, 0, 0); $this->assertInstanceOf(Colorspace::class, $color->colorspace()); } public function testChannels(): void { $color = new Color(10, 20, 30); $this->assertIsArray($color->channels()); $this->assertCount(3, $color->channels()); } public function testChannel(): void { $color = new Color(10, 20, 30); $channel = $color->channel(Hue::class); $this->assertInstanceOf(Hue::class, $channel); $this->assertEquals(10, $channel->value()); } public function testChannelNotFound(): void { $color = new Color(10, 20, 30); $this->expectException(ColorException::class); $color->channel('none'); } public function testHueSaturationLuminanceKey(): void { $color = new Color(10, 20, 30); $this->assertInstanceOf(Hue::class, $color->hue()); $this->assertInstanceOf(Saturation::class, $color->saturation()); $this->assertInstanceOf(Luminance::class, $color->luminance()); $this->assertEquals(10, $color->hue()->value()); $this->assertEquals(20, $color->saturation()->value()); $this->assertEquals(30, $color->luminance()->value()); } public function testToArray(): void { $color = new Color(10, 20, 30); $this->assertEquals([10, 20, 30], $color->toArray()); } public function testToHex(): void { $color = new Color(16, 100, 50); $this->assertEquals('ff4400', $color->toHex()); } public function testNormalize(): void { $color = new Color(180, 50, 25); $this->assertEquals([.5, 0.5, 0.25], $color->normalize()); } public function testToString(): void { $color = new Color(100, 50, 20, 0); $this->assertEquals('hsl(100, 50%, 20%)', (string) $color); } public function testIsGreyscale(): void { $color = new Color(0, 1, 0); $this->assertFalse($color->isGreyscale()); $color = new Color(1, 0, 0); $this->assertTrue($color->isGreyscale()); $color = new Color(0, 0, 1); $this->assertTrue($color->isGreyscale()); } public function testIsTransparent(): void { $color = new Color(0, 1, 0); $this->assertFalse($color->isTransparent()); } public function testIsClear(): void { $color = new Color(0, 1, 0); $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']); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsl/ChannelTest.php
tests/Unit/Colors/Hsl/ChannelTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsl; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Hsl\Channels\Hue; use Intervention\Image\Colors\Hsl\Channels\Saturation; use Intervention\Image\Colors\Hsl\Channels\Luminance; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Hue::class)] #[CoversClass(Saturation::class)] #[CoversClass(Luminance::class)] final class ChannelTest extends BaseTestCase { public function testConstructor(): void { $channel = new Hue(0); $this->assertInstanceOf(Hue::class, $channel); $channel = new Hue(value: 0); $this->assertInstanceOf(Hue::class, $channel); $channel = new Hue(normalized: 0); $this->assertInstanceOf(Hue::class, $channel); $this->expectException(ColorException::class); new Hue(); $this->expectException(ColorException::class); new Hue(normalized: 2); } public function testConstructorFail(): void { $this->expectException(ColorException::class); new Hue(400); } public function testToInt(): void { $channel = new Hue(10); $this->assertEquals(10, $channel->toInt()); } public function testToString(): void { $channel = new Hue(10); $this->assertEquals("10", $channel->toString()); $this->assertEquals("10", (string) $channel); } public function testValue(): void { $channel = new Hue(10); $this->assertEquals(10, $channel->value()); } public function testNormalize(): void { $channel = new Hue(360); $this->assertEquals(1, $channel->normalize()); $channel = new Hue(180); $this->assertEquals(0.5, $channel->normalize()); $channel = new Hue(0); $this->assertEquals(0, $channel->normalize()); $channel = new Luminance(90); $this->assertEquals(.9, $channel->normalize()); } public function testValidate(): void { $this->expectException(ColorException::class); new Hue(361); $this->expectException(ColorException::class); new Hue(-1); $this->expectException(ColorException::class); new Saturation(101); $this->expectException(ColorException::class); new Saturation(-1); $this->expectException(ColorException::class); new Luminance(101); $this->expectException(ColorException::class); new Luminance(-1); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsl/ColorspaceTest.php
tests/Unit/Colors/Hsl/ColorspaceTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsl; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Hsl\Channels\Hue; use Intervention\Image\Colors\Hsl\Channels\Luminance; use Intervention\Image\Colors\Hsl\Channels\Saturation; use Intervention\Image\Colors\Hsl\Color as HslColor; use Intervention\Image\Colors\Rgb\Color as RgbColor; use Intervention\Image\Colors\Hsv\Color as HsvColor; use Intervention\Image\Colors\Hsl\Colorspace; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Colorspace::class)] final class ColorspaceTest extends BaseTestCase { public function testColorFromNormalized(): void { $colorspace = new Colorspace(); $result = $colorspace->colorFromNormalized([1, 0, 1]); $this->assertInstanceOf(HslColor::class, $result); $this->assertEquals(360, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(100, $result->channel(Luminance::class)->value()); } public function testImportRgbColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new RgbColor(255, 0, 255)); $this->assertInstanceOf(HslColor::class, $result); $this->assertEquals(300, $result->channel(Hue::class)->value()); $this->assertEquals(100, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Luminance::class)->value()); $result = $colorspace->importColor(new RgbColor(127, 127, 127)); $this->assertInstanceOf(HslColor::class, $result); $this->assertEquals(0, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Luminance::class)->value()); $result = $colorspace->importColor(new RgbColor(255, 0, 0, 85)); $this->assertInstanceOf(HslColor::class, $result); $this->assertEquals(0, $result->channel(Hue::class)->value()); $this->assertEquals(100, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Luminance::class)->value()); } public function testImportCmykColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new CmykColor(0, 100, 0, 0)); $this->assertInstanceOf(HslColor::class, $result); $this->assertEquals(300, $result->channel(Hue::class)->value()); $this->assertEquals(100, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Luminance::class)->value()); $result = $colorspace->importColor(new CmykColor(0, 0, 0, 50)); $this->assertInstanceOf(HslColor::class, $result); $this->assertEquals(0, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Luminance::class)->value()); } public function testImportHsvColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new HsvColor(300, 100, 100)); $this->assertInstanceOf(HslColor::class, $result); $this->assertEquals(300, $result->channel(Hue::class)->value()); $this->assertEquals(100, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Luminance::class)->value()); $result = $colorspace->importColor(new HsvColor(0, 0, 50)); $this->assertInstanceOf(HslColor::class, $result); $this->assertEquals(0, $result->channel(Hue::class)->value()); $this->assertEquals(0, $result->channel(Saturation::class)->value()); $this->assertEquals(50, $result->channel(Luminance::class)->value()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsl/Channels/SaturationTest.php
tests/Unit/Colors/Hsl/Channels/SaturationTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsl\Channels; use Intervention\Image\Colors\Hsl\Channels\Saturation; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Saturation::class)] final class SaturationTest extends BaseTestCase { public function testMinMax(): void { $saturation = new Saturation(0); $this->assertEquals(0, $saturation->min()); $this->assertEquals(100, $saturation->max()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php
tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Hsl\Decoders; use Generator; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Hsl\Color; use Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(StringColorDecoder::class)] final class StringColorDecoderTest extends BaseTestCase { /** * @param $channelValues array<int> */ #[DataProvider('decodeDataProvier')] public function testDecode(string $input, string $classname, array $channelValues): void { $decoder = new StringColorDecoder(); $result = $decoder->decode($input); $this->assertInstanceOf($classname, $result); $this->assertEquals($channelValues, $result->toArray()); } public static function decodeDataProvier(): Generator { yield [ 'hsl(0,0,0)', Color::class, [0, 0, 0], ]; yield [ 'hsl(0, 100, 50)', Color::class, [0, 100, 50], ]; yield [ 'hsl(360, 100, 50)', Color::class, [360, 100, 50], ]; yield [ 'hsl(180, 100%, 50%)', Color::class, [180, 100, 50], ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Rgb/ColorTest.php
tests/Unit/Colors/Rgb/ColorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Rgb; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Blue; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Color::class)] final class ColorTest extends BaseTestCase { public function testConstructor(): void { $color = new Color(0, 0, 0); $this->assertInstanceOf(Color::class, $color); $color = new Color(0, 0, 0, 0); $this->assertInstanceOf(Color::class, $color); } public function testCreate(): void { $color = Color::create('ccc'); $this->assertInstanceOf(Color::class, $color); $this->assertEquals([204, 204, 204, 255], $color->toArray()); $color = Color::create('rgba(10, 20, 30, .2)'); $this->assertInstanceOf(Color::class, $color); $this->assertEquals([10, 20, 30, 51], $color->toArray()); } public function testColorspace(): void { $color = new Color(0, 0, 0); $this->assertInstanceOf(RgbColorspace::class, $color->colorspace()); } public function testChannels(): void { $color = new Color(10, 20, 30); $this->assertIsArray($color->channels()); $this->assertCount(4, $color->channels()); } public function testChannel(): void { $color = new Color(10, 20, 30); $channel = $color->channel(Red::class); $this->assertInstanceOf(Red::class, $channel); $this->assertEquals(10, $channel->value()); } public function testChannelNotFound(): void { $color = new Color(10, 20, 30); $this->expectException(ColorException::class); $color->channel('none'); } public function testRedGreenBlue(): void { $color = new Color(10, 20, 30); $this->assertInstanceOf(Red::class, $color->red()); $this->assertInstanceOf(Green::class, $color->green()); $this->assertInstanceOf(Blue::class, $color->blue()); $this->assertEquals(10, $color->red()->value()); $this->assertEquals(20, $color->green()->value()); $this->assertEquals(30, $color->blue()->value()); } public function testToArray(): void { $color = new Color(10, 20, 30); $this->assertEquals([10, 20, 30, 255], $color->toArray()); } public function testToHex(): void { $color = new Color(181, 55, 23); $this->assertEquals('b53717', $color->toHex()); $this->assertEquals('#b53717', $color->toHex('#')); $color = new Color(181, 55, 23, 51); $this->assertEquals('b5371733', $color->toHex()); } public function testNormalize(): void { $color = new Color(255, 0, 51); $this->assertEquals([1.0, 0.0, 0.2, 1.0], $color->normalize()); } public function testToString(): void { $color = new Color(181, 55, 23); $this->assertEquals('rgb(181, 55, 23)', (string) $color); } public function testConvertTo(): void { $color = new Color(0, 0, 0); $converted = $color->convertTo(CmykColorspace::class); $this->assertInstanceOf(CmykColor::class, $converted); $this->assertEquals([0, 0, 0, 100], $converted->toArray()); $color = new Color(255, 255, 255); $converted = $color->convertTo(CmykColorspace::class); $this->assertInstanceOf(CmykColor::class, $converted); $this->assertEquals([0, 0, 0, 0], $converted->toArray()); $color = new Color(255, 0, 0); $converted = $color->convertTo(CmykColorspace::class); $this->assertInstanceOf(CmykColor::class, $converted); $this->assertEquals([0, 100, 100, 0], $converted->toArray()); $color = new Color(255, 0, 255); $converted = $color->convertTo(CmykColorspace::class); $this->assertInstanceOf(CmykColor::class, $converted); $this->assertEquals([0, 100, 0, 0], $converted->toArray()); $color = new Color(255, 255, 0); $converted = $color->convertTo(CmykColorspace::class); $this->assertInstanceOf(CmykColor::class, $converted); $this->assertEquals([0, 0, 100, 0], $converted->toArray()); $color = new Color(255, 204, 204); $converted = $color->convertTo(CmykColorspace::class); $this->assertInstanceOf(CmykColor::class, $converted); $this->assertEquals([0, 20, 20, 0], $converted->toArray()); } public function testIsGreyscale(): void { $color = new Color(255, 0, 100); $this->assertFalse($color->isGreyscale()); $color = new Color(50, 50, 50); $this->assertTrue($color->isGreyscale()); } public function testIsTransparent(): void { $color = new Color(255, 255, 255); $this->assertFalse($color->isTransparent()); $color = new Color(255, 255, 255, 255); $this->assertFalse($color->isTransparent()); $color = new Color(255, 255, 255, 85); $this->assertTrue($color->isTransparent()); $color = new Color(255, 255, 255, 0); $this->assertTrue($color->isTransparent()); } public function testIsClear(): void { $color = new Color(255, 255, 255); $this->assertFalse($color->isClear()); $color = new Color(255, 255, 255, 255); $this->assertFalse($color->isClear()); $color = new Color(255, 255, 255, 85); $this->assertFalse($color->isClear()); $color = new Color(255, 255, 255, 0); $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']); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Rgb/ChannelTest.php
tests/Unit/Colors/Rgb/ChannelTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Rgb; use Intervention\Image\Colors\Rgb\Channels\Blue; use Intervention\Image\Colors\Rgb\Channels\Green; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Rgb\Channels\Red as Channel; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Red::class)] #[CoversClass(Green::class)] #[CoversClass(Blue::class)] final class ChannelTest extends BaseTestCase { public function testConstructor(): void { $channel = new Channel(0); $this->assertInstanceOf(Channel::class, $channel); $channel = new Channel(value: 0); $this->assertInstanceOf(Channel::class, $channel); $channel = new Channel(normalized: 0); $this->assertInstanceOf(Channel::class, $channel); $this->expectException(ColorException::class); new Channel(); $this->expectException(ColorException::class); new Channel(normalized: 2); } public function testConstructorFail(): void { $this->expectException(ColorException::class); new Channel(300); } public function testToInt(): void { $channel = new Channel(255); $this->assertEquals(255, $channel->toInt()); } public function testToString(): void { $channel = new Channel(10); $this->assertEquals("10", $channel->toString()); $this->assertEquals("10", (string) $channel); } public function testValue(): void { $channel = new Channel(10); $this->assertEquals(10, $channel->value()); } public function testNormalize(): void { $channel = new Channel(255); $this->assertEquals(1, $channel->normalize()); $channel = new Channel(0); $this->assertEquals(0, $channel->normalize()); $channel = new Channel(51); $this->assertEquals(.2, $channel->normalize()); } public function testValidate(): void { $this->expectException(ColorException::class); new Channel(256); $this->expectException(ColorException::class); new Channel(-1); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Rgb/ColorspaceTest.php
tests/Unit/Colors/Rgb/ColorspaceTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Rgb; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Hsv\Color as HsvColor; use Intervention\Image\Colors\Rgb\Channels\Blue; use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Color as RgbColor; use Intervention\Image\Colors\Hsl\Color as HslColor; use Intervention\Image\Colors\Rgb\Channels\Alpha; use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Colorspace::class)] final class ColorspaceTest extends BaseTestCase { public function testColorFromNormalized(): void { $colorspace = new Colorspace(); $result = $colorspace->colorFromNormalized([1, 0, 1, 1]); $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals(255, $result->channel(Red::class)->value()); $this->assertEquals(0, $result->channel(Green::class)->value()); $this->assertEquals(255, $result->channel(Blue::class)->value()); $this->assertEquals(255, $result->channel(Alpha::class)->value()); } public function testImportCmykColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new CmykColor(0, 100, 0, 0)); $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals(255, $result->channel(Red::class)->value()); $this->assertEquals(0, $result->channel(Green::class)->value()); $this->assertEquals(255, $result->channel(Blue::class)->value()); $result = $colorspace->importColor(new CmykColor(0, 0, 0, 50)); $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals(127, $result->channel(Red::class)->value()); $this->assertEquals(127, $result->channel(Green::class)->value()); $this->assertEquals(127, $result->channel(Blue::class)->value()); } public function testImportHsvColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new HsvColor(300, 100, 100)); $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals(255, $result->channel(Red::class)->value()); $this->assertEquals(0, $result->channel(Green::class)->value()); $this->assertEquals(255, $result->channel(Blue::class)->value()); $result = $colorspace->importColor(new HsvColor(0, 0, 50)); $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals(128, $result->channel(Red::class)->value()); $this->assertEquals(128, $result->channel(Green::class)->value()); $this->assertEquals(128, $result->channel(Blue::class)->value()); } public function testImportHslColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new HslColor(300, 100, 50)); $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals(255, $result->channel(Red::class)->value()); $this->assertEquals(0, $result->channel(Green::class)->value()); $this->assertEquals(255, $result->channel(Blue::class)->value()); $result = $colorspace->importColor(new HslColor(0, 0, 50)); $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals(128, $result->channel(Red::class)->value()); $this->assertEquals(128, $result->channel(Green::class)->value()); $this->assertEquals(128, $result->channel(Blue::class)->value()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Rgb/Channels/AlphaTest.php
tests/Unit/Colors/Rgb/Channels/AlphaTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Rgb\Channels; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Rgb\Channels\Alpha; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Alpha::class)] final class AlphaTest extends BaseTestCase { public function testToString(): void { $alpha = new Alpha(255 / 3); $this->assertEquals('0.333333', $alpha->toString()); $this->assertEquals('0.333333', (string) $alpha); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php
tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Rgb\Decoders; use Generator; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(StringColorDecoder::class)] final class StringColorDecoderTest extends BaseTestCase { /** * @param $channelValues array<int> */ #[DataProvider('decodeDataProvier')] public function testDecode(string $input, string $classname, array $channelValues): void { $decoder = new StringColorDecoder(); $result = $decoder->decode($input); $this->assertInstanceOf($classname, $result); $this->assertEquals($channelValues, $result->toArray()); } public static function decodeDataProvier(): Generator { yield [ 'rgb(204, 204, 204)', Color::class, [204, 204, 204, 255], ]; yield [ 'rgb(204,204,204)', Color::class, [204, 204, 204, 255], ]; yield [ 'rgb(100%,20%,0%)', Color::class, [255, 51, 0, 255], ]; yield [ 'rgb(100%,19.8064%,0.1239483%)', Color::class, [255, 51, 0, 255], ]; yield [ 'rgba(204, 204, 204, 1)', Color::class, [204, 204, 204, 255], ]; yield [ 'rgba(204,204,204,.2)', Color::class, [204, 204, 204, 51], ]; yield [ 'rgba(204,204,204,0.2)', Color::class, [204, 204, 204, 51], ]; yield [ 'srgb(255, 0, 0)', Color::class, [255, 0, 0, 255], ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php
tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Rgb\Decoders; use Generator; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(HtmlColorNameDecoder::class)] final class HtmlColornameDecoderTest extends BaseTestCase { /** * @param $channelValues array<int> */ #[DataProvider('decodeDataProvier')] public function testDecode(string $input, string $classname, array $channelValues): void { $decoder = new HtmlColornameDecoder(); $result = $decoder->decode($input); $this->assertInstanceOf($classname, $result); $this->assertEquals($channelValues, $result->toArray()); } public static function decodeDataProvier(): Generator { yield [ 'salmon', Color::class, [250, 128, 114, 255], ]; yield [ 'khaki', Color::class, [240, 230, 140, 255], ]; yield [ 'peachpuff', Color::class, [255, 218, 185, 255], ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php
tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Rgb\Decoders; use Generator; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(HexColorDecoder::class)] final class HexColorDecoderTest extends BaseTestCase { /** * @param $channelValues array<int> */ #[DataProvider('decodeDataProvier')] public function testDecode(string $input, string $classname, array $channelValues): void { $decoder = new HexColorDecoder(); $result = $decoder->decode($input); $this->assertInstanceOf($classname, $result); $this->assertEquals($channelValues, $result->toArray()); } public static function decodeDataProvier(): Generator { yield [ 'ccc', Color::class, [204, 204, 204, 255] ]; yield [ 'ccff33', Color::class, [204, 255, 51, 255], ]; yield [ '#ccc', Color::class, [204, 204, 204, 255], ]; yield [ 'cccccc', Color::class, [204, 204, 204, 255], ]; yield [ '#cccccc', Color::class, [204, 204, 204, 255], ]; yield [ '#ccccccff', Color::class, [204, 204, 204, 255], ]; yield [ '#cccf', Color::class, [204, 204, 204, 255], ]; yield [ 'ccccccff', Color::class, [204, 204, 204, 255], ]; yield [ 'cccf', Color::class, [204, 204, 204, 255], ]; yield [ '#b53717aa', Color::class, [181, 55, 23, 170], ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Cmyk/ColorTest.php
tests/Unit/Colors/Cmyk/ColorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Cmyk; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Cmyk\Channels\Cyan; use Intervention\Image\Colors\Cmyk\Channels\Key; use Intervention\Image\Colors\Cmyk\Channels\Magenta; use Intervention\Image\Colors\Cmyk\Channels\Yellow; use Intervention\Image\Colors\Cmyk\Color; use Intervention\Image\Colors\Cmyk\Colorspace; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Color::class)] final class ColorTest extends BaseTestCase { public function testConstructor(): void { $color = new Color(0, 0, 0, 0); $this->assertInstanceOf(Color::class, $color); } public function testCreate(): void { $color = Color::create('cmyk(10, 20, 30, 40)'); $this->assertInstanceOf(Color::class, $color); } public function testColorspace(): void { $color = new Color(0, 0, 0, 0); $this->assertInstanceOf(Colorspace::class, $color->colorspace()); } public function testChannels(): void { $color = new Color(10, 20, 30, 40); $this->assertIsArray($color->channels()); $this->assertCount(4, $color->channels()); } public function testChannel(): void { $color = new Color(10, 20, 30, 40); $channel = $color->channel(Cyan::class); $this->assertInstanceOf(Cyan::class, $channel); $this->assertEquals(10, $channel->value()); } public function testChannelNotFound(): void { $color = new Color(10, 20, 30, 30); $this->expectException(ColorException::class); $color->channel('none'); } public function testCyanMagentaYellowKey(): void { $color = new Color(10, 20, 30, 40); $this->assertInstanceOf(Cyan::class, $color->cyan()); $this->assertInstanceOf(Magenta::class, $color->magenta()); $this->assertInstanceOf(Yellow::class, $color->yellow()); $this->assertInstanceOf(Key::class, $color->key()); $this->assertEquals(10, $color->cyan()->value()); $this->assertEquals(20, $color->magenta()->value()); $this->assertEquals(30, $color->yellow()->value()); $this->assertEquals(40, $color->key()->value()); } public function testToArray(): void { $color = new Color(10, 20, 30, 40); $this->assertEquals([10, 20, 30, 40], $color->toArray()); } public function testToHex(): void { $color = new Color(0, 73, 100, 0); $this->assertEquals('ff4400', $color->toHex()); $this->assertEquals('#ff4400', $color->toHex('#')); } public function testIsGreyscale(): void { $color = new Color(0, 73, 100, 0); $this->assertFalse($color->isGreyscale()); $color = new Color(0, 0, 0, 50); $this->assertTrue($color->isGreyscale()); } public function testNormalize(): void { $color = new Color(100, 50, 20, 0); $this->assertEquals([1.0, 0.5, 0.2, 0.0], $color->normalize()); } public function testToString(): void { $color = new Color(100, 50, 20, 0); $this->assertEquals('cmyk(100%, 50%, 20%, 0%)', (string) $color); } public function testIsTransparent(): void { $color = new Color(100, 50, 50, 0); $this->assertFalse($color->isTransparent()); } public function testIsClear(): void { $color = new Color(0, 0, 0, 0); $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']); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Cmyk/ChannelTest.php
tests/Unit/Colors/Cmyk/ChannelTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Cmyk; use Intervention\Image\Colors\Cmyk\Channels\Cyan; use Intervention\Image\Colors\Cmyk\Channels\Key; use Intervention\Image\Colors\Cmyk\Channels\Magenta; use Intervention\Image\Colors\Cmyk\Channels\Yellow; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Cyan::class)] #[CoversClass(Magenta::class)] #[CoversClass(Yellow::class)] #[CoversClass(Key::class)] final class ChannelTest extends BaseTestCase { public function testConstructor(): void { $channel = new Cyan(0); $this->assertInstanceOf(Cyan::class, $channel); $channel = new Cyan(value: 0); $this->assertInstanceOf(Cyan::class, $channel); $channel = new Cyan(normalized: 0); $this->assertInstanceOf(Cyan::class, $channel); $this->expectException(ColorException::class); new Cyan(); $this->expectException(ColorException::class); new Cyan(normalized: 2); } public function testConstructorFail(): void { $this->expectException(ColorException::class); new Cyan(200); } public function testToInt(): void { $channel = new Cyan(10); $this->assertEquals(10, $channel->toInt()); } public function testToString(): void { $channel = new Cyan(10); $this->assertEquals("10", $channel->toString()); $this->assertEquals("10", (string) $channel); } public function testValue(): void { $channel = new Cyan(10); $this->assertEquals(10, $channel->value()); } public function testNormalize(): void { $channel = new Cyan(100); $this->assertEquals(1, $channel->normalize()); $channel = new Cyan(0); $this->assertEquals(0, $channel->normalize()); $channel = new Cyan(20); $this->assertEquals(.2, $channel->normalize()); } public function testValidate(): void { $this->expectException(ColorException::class); new Cyan(101); $this->expectException(ColorException::class); new Cyan(-1); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Cmyk/ColorspaceTest.php
tests/Unit/Colors/Cmyk/ColorspaceTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Cmyk; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Cmyk\Channels\Cyan; use Intervention\Image\Colors\Cmyk\Channels\Key; use Intervention\Image\Colors\Cmyk\Channels\Magenta; use Intervention\Image\Colors\Cmyk\Channels\Yellow; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Rgb\Color as RgbColor; use Intervention\Image\Colors\Hsv\Color as HsvColor; use Intervention\Image\Colors\Hsl\Color as HslColor; use Intervention\Image\Colors\Cmyk\Colorspace; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(Colorspace::class)] final class ColorspaceTest extends BaseTestCase { public function testColorFromNormalized(): void { $colorspace = new Colorspace(); $result = $colorspace->colorFromNormalized([0, 1, 0, 1]); $this->assertInstanceOf(CmykColor::class, $result); $this->assertEquals(0, $result->channel(Cyan::class)->value()); $this->assertEquals(100, $result->channel(Magenta::class)->value()); $this->assertEquals(0, $result->channel(Yellow::class)->value()); $this->assertEquals(100, $result->channel(Key::class)->value()); } public function testImportRgbColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new RgbColor(255, 0, 255)); $this->assertInstanceOf(CmykColor::class, $result); $this->assertEquals(0, $result->channel(Cyan::class)->value()); $this->assertEquals(100, $result->channel(Magenta::class)->value()); $this->assertEquals(0, $result->channel(Yellow::class)->value()); $this->assertEquals(0, $result->channel(Key::class)->value()); $result = $colorspace->importColor(new RgbColor(127, 127, 127)); $this->assertInstanceOf(CmykColor::class, $result); $this->assertEquals(0, $result->channel(Cyan::class)->value()); $this->assertEquals(0, $result->channel(Magenta::class)->value()); $this->assertEquals(0, $result->channel(Yellow::class)->value()); $this->assertEquals(50, $result->channel(Key::class)->value()); $result = $colorspace->importColor(new RgbColor(127, 127, 127, 85)); $this->assertInstanceOf(CmykColor::class, $result); $this->assertEquals(0, $result->channel(Cyan::class)->value()); $this->assertEquals(0, $result->channel(Magenta::class)->value()); $this->assertEquals(0, $result->channel(Yellow::class)->value()); $this->assertEquals(50, $result->channel(Key::class)->value()); } public function testImportHsvColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new HsvColor(0, 0, 50)); $this->assertInstanceOf(CmykColor::class, $result); $this->assertEquals(0, $result->channel(Cyan::class)->value()); $this->assertEquals(0, $result->channel(Magenta::class)->value()); $this->assertEquals(0, $result->channel(Yellow::class)->value()); $this->assertEquals(50, $result->channel(Key::class)->value()); } public function testImportHslColor(): void { $colorspace = new Colorspace(); $result = $colorspace->importColor(new HslColor(300, 100, 50)); $this->assertInstanceOf(CmykColor::class, $result); $this->assertEquals(0, $result->channel(Cyan::class)->value()); $this->assertEquals(100, $result->channel(Magenta::class)->value()); $this->assertEquals(0, $result->channel(Yellow::class)->value()); $this->assertEquals(0, $result->channel(Key::class)->value()); $result = $colorspace->importColor(new HslColor(0, 0, 50)); $this->assertInstanceOf(CmykColor::class, $result); $this->assertEquals(0, $result->channel(Cyan::class)->value()); $this->assertEquals(0, $result->channel(Magenta::class)->value()); $this->assertEquals(0, $result->channel(Yellow::class)->value()); $this->assertEquals(50, $result->channel(Key::class)->value()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Colors/Cmyk/Decoders/StringColorDecoderTest.php
tests/Unit/Colors/Cmyk/Decoders/StringColorDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Colors\Cmyk\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use Intervention\Image\Colors\Cmyk\Color; use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Tests\BaseTestCase; #[CoversClass(StringColorDecoder::class)] final class StringColorDecoderTest extends BaseTestCase { public function testDecode(): void { $decoder = new StringColorDecoder(); $result = $decoder->decode('cmyk(0,0,0,0)'); $this->assertInstanceOf(Color::class, $result); $this->assertEquals([0, 0, 0, 0], $result->toArray()); $result = $decoder->decode('cmyk(0, 100, 100, 0)'); $this->assertInstanceOf(Color::class, $result); $this->assertEquals([0, 100, 100, 0], $result->toArray()); $result = $decoder->decode('cmyk(0, 100, 100, 0)'); $this->assertInstanceOf(Color::class, $result); $this->assertEquals([0, 100, 100, 0], $result->toArray()); $result = $decoder->decode('cmyk(0%, 100%, 100%, 0%)'); $this->assertInstanceOf(Color::class, $result); $this->assertEquals([0, 100, 100, 0], $result->toArray()); } public function testDecodeInvalid(): void { $decoder = new StringColorDecoder(); $this->expectException(DecoderException::class); $decoder->decode(null); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/AbstractEncoderTest.php
tests/Unit/Drivers/AbstractEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers; use Intervention\Image\EncodedImage; use Intervention\Image\Drivers\AbstractEncoder; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Tests\BaseTestCase; use Mockery; use PHPUnit\Metadata\CoversClass; #[CoversClass(AbstractEncoder::class)] final class AbstractEncoderTest extends BaseTestCase { public function testEncode(): void { $encoder = Mockery::mock(AbstractEncoder::class)->makePartial(); $image = Mockery::mock(ImageInterface::class); $encoded = Mockery::mock(EncodedImage::class); $image->shouldReceive('encode')->andReturn($encoded); $result = $encoder->encode($image); $this->assertInstanceOf(EncodedImage::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/SpecializableAnalyzerTest.php
tests/Unit/Drivers/SpecializableAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers; use Intervention\Image\Drivers\SpecializableAnalyzer; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Tests\BaseTestCase; use Mockery; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(SpecializableAnalyzer::class)] final class SpecializableAnalyzerTest extends BaseTestCase { public function testAnalyze(): void { $analyzer = Mockery::mock(SpecializableAnalyzer::class)->makePartial(); $image = Mockery::mock(ImageInterface::class); $image->shouldReceive('analyze')->andReturn('test'); $result = $analyzer->analyze($image); $this->assertEquals('test', $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/SpecializableDecoderTest.php
tests/Unit/Drivers/SpecializableDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers; use Intervention\Image\Drivers\SpecializableDecoder; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Tests\BaseTestCase; use Mockery; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(SpecializableDecoder::class)] final class SpecializableDecoderTest extends BaseTestCase { public function testDecode(): void { $decoder = Mockery::mock(SpecializableDecoder::class)->makePartial(); $this->expectException(DecoderException::class); $decoder->decode(null); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/AbstractDecoderTest.php
tests/Unit/Drivers/AbstractDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers; use PHPUnit\Framework\Attributes\CoversClass; use Exception; use Intervention\Image\Drivers\AbstractDecoder; use Intervention\Image\Interfaces\CollectionInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Tests\BaseTestCase; use Mockery; use stdClass; #[CoversClass(AbstractDecoder::class)] final class AbstractDecoderTest extends BaseTestCase { public function testIsGifFormat(): void { $decoder = Mockery::mock(AbstractDecoder::class); $this->assertFalse($decoder->isGifFormat($this->getTestResourceData('exif.jpg'))); $this->assertTrue($decoder->isGifFormat($this->getTestResourceData('red.gif'))); } public function testIsFile(): void { $decoder = Mockery::mock(AbstractDecoder::class); $this->assertTrue($decoder->isFile($this->getTestResourcePath())); $this->assertFalse($decoder->isFile('non-existent-file')); $this->assertFalse($decoder->isFile(new stdClass())); $this->assertFalse($decoder->isFile(str_repeat('o', PHP_MAXPATHLEN + 1))); $this->assertFalse($decoder->isFile(__DIR__)); } public function testExtractExifDataFromBinary(): void { $source = $this->getTestResourceData('exif.jpg'); $pointer = $this->getTestResourcePointer('exif.jpg'); $decoder = Mockery::mock(AbstractDecoder::class); $decoder->shouldReceive('buildFilePointer')->with($source)->andReturn($pointer); $result = $decoder->extractExifData($source); $this->assertInstanceOf(CollectionInterface::class, $result); $this->assertEquals('Oliver Vogel', $result->get('IFD0.Artist')); } public function testExtractExifDataFromPath(): void { $decoder = Mockery::mock(AbstractDecoder::class); $result = $decoder->extractExifData($this->getTestResourcePath('exif.jpg')); $this->assertInstanceOf(CollectionInterface::class, $result); $this->assertEquals('Oliver Vogel', $result->get('IFD0.Artist')); } public function testParseDataUri(): void { $decoder = new class () extends AbstractDecoder { public function parse(mixed $input): object { return parent::parseDataUri($input); } public function decode(mixed $input): ImageInterface|ColorInterface { throw new Exception(''); } }; $result = $decoder->parse( 'data:image/gif;foo=bar;base64,R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7' ); $this->assertTrue($result->isValid()); $this->assertEquals('image/gif', $result->mediaType()); $this->assertTrue($result->hasMediaType()); $this->assertTrue($result->isBase64Encoded()); $this->assertEquals( 'R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7', $result->data() ); $result = $decoder->parse('data:text/plain;charset=utf-8,test'); $this->assertTrue($result->isValid()); $this->assertEquals('text/plain', $result->mediaType()); $this->assertTrue($result->hasMediaType()); $this->assertFalse($result->isBase64Encoded()); $this->assertEquals('test', $result->data()); $result = $decoder->parse('data:;charset=utf-8,'); $this->assertTrue($result->isValid()); $this->assertNull($result->mediaType()); $this->assertFalse($result->hasMediaType()); $this->assertFalse($result->isBase64Encoded()); $this->assertNull($result->data()); } public function testIsValidBase64(): void { $decoder = new class () extends AbstractDecoder { public function isValid(mixed $input): bool { return parent::isValidBase64($input); } public function decode(mixed $input): ImageInterface|ColorInterface { throw new Exception(''); } }; $this->assertTrue( $decoder->isValid('R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7') ); $this->assertFalse( $decoder->isValid('foo') ); $this->assertFalse( $decoder->isValid(new stdClass()) ); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/AbstractFontProcessorTest.php
tests/Unit/Drivers/AbstractFontProcessorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers; use Intervention\Image\Drivers\AbstractFontProcessor; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\Font; use Intervention\Image\Typography\TextBlock; use Mockery; use PHPUnit\Metadata\CoversClass; #[CoversClass(AbstractFontProcessor::class)] class AbstractFontProcessorTest extends BaseTestCase { public function testTextBlock(): void { $text = 'AAAA BBBB CCCC'; $font = (new Font($this->getTestResourcePath('test.ttf'))) ->setWrapWidth(20) ->setSize(50) ->setLineHeight(1.25) ->setAlignment('center'); $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); $processor ->shouldReceive('boxSize') ->with('T', $font) ->andReturn(new Rectangle(12, 6)); $processor ->shouldReceive('boxSize') ->with('Hy', $font) ->andReturn(new Rectangle(24, 6)); $processor ->shouldReceive('boxSize') ->with('AAAA', $font) ->andReturn(new Rectangle(24, 6, new Point(1000, 0))); $processor ->shouldReceive('boxSize') ->with('AAAA BBBB', $font) ->andReturn(new Rectangle(24, 6)); $processor ->shouldReceive('boxSize') ->with('BBBB', $font) ->andReturn(new Rectangle(24, 6, new Point(2000, 0))); $processor ->shouldReceive('boxSize') ->with('BBBB CCCC', $font) ->andReturn(new Rectangle(24, 6)); $processor ->shouldReceive('boxSize') ->with('CCCC', $font) ->andReturn(new Rectangle(24, 6, new Point(3000, 0))); $processor ->shouldReceive('boxSize') ->with($text, $font) ->andReturn(new Rectangle(100, 25, new Point(10, 0))); $block = $processor->textBlock($text, $font, new Point(0, 0)); $this->assertInstanceOf(TextBlock::class, $block); $this->assertEquals(3, $block->count()); $this->assertEquals(-512, $block->getAtPosition(0)->position()->x()); $this->assertEquals(-16, $block->getAtPosition(0)->position()->y()); $this->assertEquals(-1012, $block->getAtPosition(1)->position()->x()); $this->assertEquals(-8, $block->getAtPosition(1)->position()->y()); $this->assertEquals(-1512, $block->getAtPosition(2)->position()->x()); $this->assertEquals(0, $block->getAtPosition(2)->position()->y()); } public function testNativeFontSize(): void { $font = (new Font($this->getTestResourcePath('test.ttf')))->setSize(32); $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); $this->assertEquals(32, $processor->nativeFontSize($font)); } public function testTypographicalSize(): void { $font = new Font($this->getTestResourcePath('test.ttf')); $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); $processor->shouldReceive('boxSize')->with('Hy', $font)->andReturn(new Rectangle(24, 6)); $this->assertEquals(6, $processor->typographicalSize($font)); } public function testCapHeight(): void { $font = new Font($this->getTestResourcePath('test.ttf')); $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); $processor->shouldReceive('boxSize')->with('T', $font)->andReturn(new Rectangle(24, 6)); $this->assertEquals(6, $processor->capHeight($font)); } public function testLeading(): void { $font = (new Font($this->getTestResourcePath('test.ttf')))->setLineHeight(3); $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); $processor->shouldReceive('boxSize')->with('Hy', $font)->andReturn(new Rectangle(24, 6)); $this->assertEquals(18, $processor->leading($font)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/SpecializableModifierTest.php
tests/Unit/Drivers/SpecializableModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers; use Intervention\Image\Drivers\SpecializableModifier; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Tests\BaseTestCase; use Mockery; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(SpecializableModifier::class)] final class SpecializableModifierTest extends BaseTestCase { public function testApply(): void { $modifier = Mockery::mock(SpecializableModifier::class)->makePartial(); $image = Mockery::mock(ImageInterface::class); $image->shouldReceive('modify')->andReturn($image); $result = $modifier->apply($image); $this->assertInstanceOf(ImageInterface::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/ImageTest.php
tests/Unit/Drivers/Gd/ImageTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd; use Intervention\Image\Analyzers\WidthAnalyzer; use Intervention\Image\Collection; use Intervention\Image\Colors\Hsl\Colorspace; use Intervention\Image\Drivers\Gd\Core; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Frame; use Intervention\Image\EncodedImage; use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Exceptions\EncoderException; use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\FileExtension; use Intervention\Image\Image; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ResolutionInterface; use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\MediaType; use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Tests\GdTestCase; use Intervention\Image\Typography\Font; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('gd')] #[CoversClass(Image::class)] final class ImageTest extends GdTestCase { protected Image $image; protected function setUp(): void { $this->image = new Image( new Driver(), new Core([ new Frame(imagecreatetruecolor(3, 2)), new Frame(imagecreatetruecolor(3, 2)), ]), new Collection([ 'test' => 'foo' ]), ); } public function testClone(): void { $image = $this->readTestImage('gradient.gif'); $clone = clone $image; $this->assertEquals(16, $image->width()); $this->assertEquals(16, $clone->width()); $result = $clone->crop(4, 4); $this->assertEquals(16, $image->width()); $this->assertEquals(4, $clone->width()); $this->assertEquals(4, $result->width()); $this->assertEquals('ff0000', $image->pickColor(0, 0)->toHex()); $this->assertTransparency($image->pickColor(1, 0)); $this->assertEquals('ff0000', $clone->pickColor(0, 0)->toHex()); $this->assertTransparency($image->pickColor(1, 0)); } public function testDriver(): void { $this->assertInstanceOf(Driver::class, $this->image->driver()); } public function testCore(): void { $this->assertInstanceOf(Core::class, $this->image->core()); } public function testCount(): void { $this->assertEquals(2, $this->image->count()); } public function testIteration(): void { foreach ($this->image as $frame) { $this->assertInstanceOf(Frame::class, $frame); } } public function testIsAnimated(): void { $this->assertTrue($this->image->isAnimated()); } public function testSetGetLoops(): void { $this->assertEquals(0, $this->image->loops()); $result = $this->image->setLoops(10); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals(10, $this->image->loops()); } public function testRemoveAnimation(): void { $this->assertTrue($this->image->isAnimated()); $result = $this->image->removeAnimation(); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertFalse($this->image->isAnimated()); } public function testSliceAnimation(): void { $this->assertEquals(2, $this->image->count()); $result = $this->image->sliceAnimation(0, 1); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals(1, $this->image->count()); } public function testExif(): void { $this->assertInstanceOf(Collection::class, $this->image->exif()); $this->assertEquals('foo', $this->image->exif('test')); } public function testModify(): void { $result = $this->image->modify(new GreyscaleModifier()); $this->assertInstanceOf(Image::class, $result); } public function testAnalyze(): void { $result = $this->image->analyze(new WidthAnalyzer()); $this->assertEquals(3, $result); } public function testEncode(): void { $result = $this->image->encode(new PngEncoder()); $this->assertInstanceOf(EncodedImage::class, $result); } public function testAutoEncode(): void { $result = $this->readTestImage('blue.gif')->encode(); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/gif', $result); } public function testEncodeByMediaType(): void { $result = $this->readTestImage('blue.gif')->encodeByMediaType(); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/gif', $result); $result = $this->readTestImage('blue.gif')->encodeByMediaType('image/png'); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/png', $result); $result = $this->readTestImage('blue.gif')->encodeByMediaType(MediaType::IMAGE_PNG); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/png', $result); } public function testEncodeByExtension(): void { $result = $this->readTestImage('blue.gif')->encodeByExtension(); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/gif', $result); $result = $this->readTestImage('blue.gif')->encodeByExtension('png'); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/png', $result); $result = $this->readTestImage('blue.gif')->encodeByExtension(FileExtension::PNG); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/png', $result); } public function testEncodeByPath(): void { $result = $this->readTestImage('blue.gif')->encodeByPath(); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/gif', $result); $result = $this->readTestImage('blue.gif')->encodeByPath('foo/bar.png'); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/png', $result); } public function testSaveAsFormat(): void { $path = __DIR__ . '/tmp.png'; $result = $this->readTestImage('blue.gif')->save($path); $this->assertInstanceOf(Image::class, $result); $this->assertFileExists($path); $this->assertMediaType('image/png', file_get_contents($path)); unlink($path); } public function testSaveFallback(): void { $path = __DIR__ . '/tmp.unknown'; $result = $this->readTestImage('blue.gif')->save($path); $this->assertInstanceOf(Image::class, $result); $this->assertFileExists($path); $this->assertMediaType('image/gif', file_get_contents($path)); unlink($path); } public function testSaveUndeterminedPath(): void { $this->expectException(EncoderException::class); $this->createTestImage(2, 3)->save(); } public function testWidthHeightSize(): void { $this->assertEquals(3, $this->image->width()); $this->assertEquals(2, $this->image->height()); $this->assertInstanceOf(SizeInterface::class, $this->image->size()); } public function testColorspace(): void { $this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace()); } public function testSetColorspace(): void { $this->expectException(NotSupportedException::class); $this->image->setColorspace(Colorspace::class); } public function testSetGetResolution(): void { $resolution = $this->image->resolution(); $this->assertInstanceOf(ResolutionInterface::class, $resolution); $this->assertEquals(96, $resolution->x()); $this->assertEquals(96, $resolution->y()); $result = $this->image->setResolution(300, 300); $resolution = $this->image->resolution(); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals(300, $resolution->x()); $this->assertEquals(300, $resolution->y()); } public function testPickColor(): void { $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0)); $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0, 1)); } public function testPickColors(): void { $result = $this->image->pickColors(0, 0); $this->assertInstanceOf(Collection::class, $result); $this->assertEquals(2, $result->count()); } public function testProfile(): void { $this->expectException(NotSupportedException::class); $this->image->profile(); } public function testReduceColors(): void { $image = $this->readTestImage(); $result = $image->reduceColors(8); $this->assertInstanceOf(ImageInterface::class, $result); } public function testSharpen(): void { $this->assertInstanceOf(Image::class, $this->image->sharpen(12)); } public function testText(): void { $this->assertInstanceOf(Image::class, $this->image->text('test', 0, 0, new Font())); } public function testBlendTransparencyDefault(): void { $image = $this->readTestImage('gradient.gif'); $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); $result = $image->blendTransparency(); $this->assertColor(255, 255, 255, 255, $image->pickColor(1, 0)); $this->assertColor(255, 255, 255, 255, $result->pickColor(1, 0)); } public function testBlendTransparencyArgument(): void { $image = $this->readTestImage('gradient.gif'); $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); $result = $image->blendTransparency('ff5500'); $this->assertColor(255, 85, 0, 255, $image->pickColor(1, 0)); $this->assertColor(255, 85, 0, 255, $result->pickColor(1, 0)); } public function testBlendTransparencyIgnoreTransparencyInBlendingColor(): void { $image = $this->readTestImage('gradient.gif'); $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); $result = $image->blendTransparency('ff550055'); $this->assertColor(255, 85, 0, 255, $image->pickColor(1, 0)); $this->assertColor(255, 85, 0, 255, $result->pickColor(1, 0)); } public function testToJpeg(): void { $this->assertMediaType('image/jpeg', $this->image->toJpeg()); $this->assertMediaType('image/jpeg', $this->image->toJpg()); } public function testToJpeg2000(): void { $this->expectException(NotSupportedException::class); $this->image->toJpeg2000(); } public function testToPng(): void { $this->assertMediaType('image/png', $this->image->toPng()); } public function testToGif(): void { $this->assertMediaType('image/gif', $this->image->toGif()); } public function testToWebp(): void { $this->assertMediaType('image/webp', $this->image->toWebp()); } public function testToBitmap(): void { $this->assertMediaTypeBitmap($this->image->toBitmap()); $this->assertMediaTypeBitmap($this->image->toBmp()); } public function testToAvif(): void { $this->assertMediaType('image/avif', $this->image->toAvif()); } public function testToTiff(): void { $this->expectException(NotSupportedException::class); $this->image->toTiff(); } public function testToHeic(): void { $this->expectException(NotSupportedException::class); $this->image->toHeic(); } public function testInvert(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex()); $result = $image->invert(); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex()); $this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex()); } public function testPixelate(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $result = $image->pixelate(10); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $this->assertEquals('6aaa8b', $image->pickColor(14, 14)->toHex()); } public function testGreyscale(): void { $image = $this->readTestImage('trim.png'); $this->assertFalse($image->pickColor(0, 0)->isGreyscale()); $result = $image->greyscale(); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertTrue($image->pickColor(0, 0)->isGreyscale()); } public function testBrightness(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $result = $image->brightness(30); $this->assertInstanceOf(ImageInterface::class, $result); $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); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/FrameTest.php
tests/Unit/Drivers/Gd/FrameTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use GdImage; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Frame; use Intervention\Image\Image; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Tests\BaseTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(Frame::class)] final class FrameTest extends BaseTestCase { protected function getTestFrame(): Frame { return new Frame(imagecreatetruecolor(3, 2)); } public function testConstructor(): void { $frame = $this->getTestFrame(); $this->assertInstanceOf(Frame::class, $frame); } public function testGetNative(): void { $frame = $this->getTestFrame(); $this->assertInstanceOf(GdImage::class, $frame->native()); } public function testSetCore(): void { $core1 = imagecreatetruecolor(3, 2); $core2 = imagecreatetruecolor(3, 3); $frame = new Frame($core1); $this->assertEquals(2, $frame->size()->height()); $result = $frame->setNative($core2); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(3, $frame->size()->height()); } public function testGetSize(): void { $frame = $this->getTestFrame(); $this->assertInstanceOf(Rectangle::class, $frame->size()); } public function testSetGetDelay(): void { $frame = $this->getTestFrame(); $this->assertEquals(0, $frame->delay()); $result = $frame->setDelay(1.5); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(1.5, $frame->delay()); } public function testSetGetDispose(): void { $frame = $this->getTestFrame(); $this->assertEquals(1, $frame->dispose()); $result = $frame->setDispose(3); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(3, $frame->dispose()); } public function testSetGetOffsetLeft(): void { $frame = $this->getTestFrame(); $this->assertEquals(0, $frame->offsetLeft()); $result = $frame->setOffsetLeft(100); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(100, $frame->offsetLeft()); } public function testSetGetOffsetTop(): void { $frame = $this->getTestFrame(); $this->assertEquals(0, $frame->offsetTop()); $result = $frame->setOffsetTop(100); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(100, $frame->offsetTop()); } public function testSetGetOffset(): void { $frame = $this->getTestFrame(); $this->assertEquals(0, $frame->offsetTop()); $this->assertEquals(0, $frame->offsetLeft()); $result = $frame->setOffset(100, 200); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(100, $frame->offsetLeft()); $this->assertEquals(200, $frame->offsetTop()); } public function testToImage(): void { $frame = $this->getTestFrame(); $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']); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/ColorProcessorTest.php
tests/Unit/Drivers/Gd/ColorProcessorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd; use Intervention\Image\Colors\Rgb\Channels\Alpha; use Intervention\Image\Colors\Rgb\Channels\Blue; use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Drivers\Gd\ColorProcessor; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('gd')] #[CoversClass(ColorProcessor::class)] final class ColorProcessorTest extends BaseTestCase { public function testColorToNative(): void { $processor = new ColorProcessor(); $result = $processor->colorToNative(new Color(255, 55, 0, 255)); $this->assertEquals(16725760, $result); } public function testNativeToColorInteger(): void { $processor = new ColorProcessor(); $result = $processor->nativeToColor(16725760); $this->assertInstanceOf(Color::class, $result); $this->assertEquals(255, $result->channel(Red::class)->value()); $this->assertEquals(55, $result->channel(Green::class)->value()); $this->assertEquals(0, $result->channel(Blue::class)->value()); $this->assertEquals(255, $result->channel(Alpha::class)->value()); } public function testNativeToColorArray(): void { $processor = new ColorProcessor(); $result = $processor->nativeToColor(['red' => 255, 'green' => 55, 'blue' => 0, 'alpha' => 0]); $this->assertInstanceOf(Color::class, $result); $this->assertEquals(255, $result->channel(Red::class)->value()); $this->assertEquals(55, $result->channel(Green::class)->value()); $this->assertEquals(0, $result->channel(Blue::class)->value()); $this->assertEquals(255, $result->channel(Alpha::class)->value()); } public function testNativeToColorInvalid(): void { $processor = new ColorProcessor(); $this->expectException(ColorException::class); $processor->nativeToColor('test'); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/ClonerTest.php
tests/Unit/Drivers/Gd/ClonerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Drivers\Gd\Cloner; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('gd')] #[CoversClass(Cloner::class)] final class ClonerTest extends BaseTestCase { public function testClone(): void { $gd = imagecreatefromgif($this->getTestResourcePath('gradient.gif')); $clone = Cloner::clone($gd); $this->assertEquals(16, imagesx($gd)); $this->assertEquals(16, imagesy($gd)); $this->assertEquals(16, imagesx($clone)); $this->assertEquals(16, imagesy($clone)); $this->assertEquals( imagecolorsforindex($gd, imagecolorat($gd, 10, 10)), imagecolorsforindex($clone, imagecolorat($clone, 10, 10)) ); } public function testCloneEmpty(): void { $gd = imagecreatefromgif($this->getTestResourcePath('gradient.gif')); $clone = Cloner::cloneEmpty($gd, new Rectangle(12, 12), new Color(255, 0, 0, 0)); $this->assertEquals(16, imagesx($gd)); $this->assertEquals(16, imagesy($gd)); $this->assertEquals(12, imagesx($clone)); $this->assertEquals(12, imagesy($clone)); $this->assertEquals( ['red' => 0, 'green' => 255, 'blue' => 2, 'alpha' => 0], imagecolorsforindex($gd, imagecolorat($gd, 10, 10)), ); $this->assertEquals( ['red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 127], imagecolorsforindex($clone, imagecolorat($clone, 10, 10)) ); } public function testCloneBlended(): void { $gd = imagecreatefromgif($this->getTestResourcePath('gradient.gif')); $clone = Cloner::cloneBlended($gd, new Color(255, 0, 255, 255)); $this->assertEquals(16, imagesx($gd)); $this->assertEquals(16, imagesy($gd)); $this->assertEquals(16, imagesx($clone)); $this->assertEquals(16, imagesy($clone)); $this->assertEquals( ['red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127], imagecolorsforindex($gd, imagecolorat($gd, 1, 0)), ); $this->assertEquals( ['red' => 255, 'green' => 0, 'blue' => 255, 'alpha' => 0], imagecolorsforindex($clone, imagecolorat($clone, 1, 0)) ); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/FontProcessorTest.php
tests/Unit/Drivers/Gd/FontProcessorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd; use Intervention\Image\Drivers\Gd\FontProcessor; use Intervention\Image\Geometry\Point; use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\Font; use Intervention\Image\Typography\TextBlock; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('gd')] #[CoversClass(FontProcessor::class)] final class FontProcessorTest extends BaseTestCase { public function testBoxSizeGdOne(): void { $processor = new FontProcessor(); $size = $processor->boxSize('test', new Font()); $this->assertInstanceOf(SizeInterface::class, $size); $this->assertEquals(16, $size->width()); $this->assertEquals(8, $size->height()); } public function testBoxSizeGdTwo(): void { $processor = new FontProcessor(); $size = $processor->boxSize('test', new Font('2')); $this->assertInstanceOf(SizeInterface::class, $size); $this->assertEquals(24, $size->width()); $this->assertEquals(14, $size->height()); } public function testBoxSizeGdThree(): void { $processor = new FontProcessor(); $size = $processor->boxSize('test', new Font('3')); $this->assertInstanceOf(SizeInterface::class, $size); $this->assertEquals(28, $size->width()); $this->assertEquals(14, $size->height()); } public function testBoxSizeGdFour(): void { $processor = new FontProcessor(); $size = $processor->boxSize('test', new Font('4')); $this->assertInstanceOf(SizeInterface::class, $size); $this->assertEquals(32, $size->width()); $this->assertEquals(16, $size->height()); } public function testBoxSizeGdFive(): void { $processor = new FontProcessor(); $size = $processor->boxSize('test', new Font('5')); $this->assertInstanceOf(SizeInterface::class, $size); $this->assertEquals(36, $size->width()); $this->assertEquals(16, $size->height()); } public function testBoxSizeTtf(): void { $processor = new FontProcessor(); $size = $processor->boxSize('ABC', $this->testFont()); $this->assertInstanceOf(SizeInterface::class, $size); $this->assertContains($size->width(), [74, 75, 76]); $this->assertContains($size->height(), [19, 20, 21]); } public function testNativeFontSize(): void { $processor = new FontProcessor(); $size = $processor->nativeFontSize(new Font('5')); $this->assertEquals(9.12, $size); } public function testTextBlock(): void { $processor = new FontProcessor(); $result = $processor->textBlock('test', new Font(), new Point(0, 0)); $this->assertInstanceOf(TextBlock::class, $result); } public function testTypographicalSize(): void { $processor = new FontProcessor(); $result = $processor->typographicalSize(new Font()); $this->assertEquals(8, $result); } public function testCapHeight(): void { $processor = new FontProcessor(); $result = $processor->capHeight(new Font()); $this->assertEquals(8, $result); } public function testLeading(): void { $processor = new FontProcessor(); $result = $processor->leading(new Font()); $this->assertEquals(8, $result); } public function testNativeFontSizeTtf(): void { $processor = new FontProcessor(); $size = $processor->nativeFontSize($this->testFont()); $this->assertEquals(42.56, $size); } public function testTextBlockTtf(): void { $processor = new FontProcessor(); $result = $processor->textBlock('test', $this->testFont(), new Point(0, 0)); $this->assertInstanceOf(TextBlock::class, $result); } public function testTypographicalSizeTtf(): void { $processor = new FontProcessor(); $result = $processor->typographicalSize($this->testFont()); $this->assertContains($result, [44, 45]); } public function testCapHeightTtf(): void { $processor = new FontProcessor(); $result = $processor->capHeight($this->testFont()); $this->assertContains($result, [44, 45]); } public function testLeadingTtf(): void { $processor = new FontProcessor(); $result = $processor->leading($this->testFont()); $this->assertContains($result, [44, 45]); } private function testFont(): Font { return (new Font($this->getTestResourcePath('test.ttf')))->setSize(56); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/CoreTest.php
tests/Unit/Drivers/Gd/CoreTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd; use GdImage; use Intervention\Image\Drivers\Gd\Core; use Intervention\Image\Drivers\Gd\Frame; use Intervention\Image\Exceptions\AnimationException; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('gd')] #[CoversClass(Core::class)] final class CoreTest extends BaseTestCase { protected Core $core; protected function setUp(): void { $this->core = new Core([ new Frame(imagecreatetruecolor(3, 2)), new Frame(imagecreatetruecolor(3, 2)), new Frame(imagecreatetruecolor(3, 2)), ]); } public function getTestFrame(): Frame { return new Frame(imagecreatetruecolor(3, 2)); } public function testAdd(): void { $this->assertEquals(3, $this->core->count()); $result = $this->core->add($this->getTestFrame()); $this->assertEquals(4, $this->core->count()); $this->assertInstanceOf(Core::class, $result); } public function testSetNative(): void { $gd1 = imagecreatetruecolor(3, 2); $gd2 = imagecreatetruecolor(3, 2); $core = new Core([new Frame($gd1)]); $this->assertEquals($gd1, $core->native()); $core->setNative($gd2); $this->assertEquals($gd2, $core->native()); } public function testCount(): void { $this->assertEquals(3, $this->core->count()); } public function testIterator(): void { foreach ($this->core as $frame) { $this->assertInstanceOf(Frame::class, $frame); } } public function testNative(): void { $this->assertInstanceOf(GdImage::class, $this->core->native()); } public function testFrame(): void { $this->assertInstanceOf(Frame::class, $this->core->frame(0)); $this->assertInstanceOf(Frame::class, $this->core->frame(1)); $this->assertInstanceOf(Frame::class, $this->core->frame(2)); $this->expectException(AnimationException::class); $this->core->frame(3); } public function testSetGetLoops(): void { $this->assertEquals(0, $this->core->loops()); $result = $this->core->setLoops(12); $this->assertInstanceOf(Core::class, $result); $this->assertEquals(12, $this->core->loops()); } public function testHas(): void { $this->assertTrue($this->core->has(0)); $this->assertTrue($this->core->has(1)); $this->assertTrue($this->core->has(2)); $this->assertFalse($this->core->has(3)); } public function testPush(): void { $this->assertEquals(3, $this->core->count()); $result = $this->core->push($this->getTestFrame()); $this->assertEquals(4, $this->core->count()); $this->assertEquals(4, $result->count()); } public function testGet(): void { $this->assertInstanceOf(Frame::class, $this->core->get(0)); $this->assertInstanceOf(Frame::class, $this->core->get(1)); $this->assertInstanceOf(Frame::class, $this->core->get(2)); $this->assertNull($this->core->get(3)); $this->assertEquals('foo', $this->core->get(3, 'foo')); } public function testEmpty(): void { $result = $this->core->empty(); $this->assertEquals(0, $this->core->count()); $this->assertEquals(0, $result->count()); } public function testSlice(): void { $this->assertEquals(3, $this->core->count()); $result = $this->core->slice(1, 2); $this->assertEquals(2, $this->core->count()); $this->assertEquals(2, $result->count()); } public function testFirst(): void { $this->assertInstanceOf(Frame::class, $this->core->first()); } public function testLast(): void { $this->assertInstanceOf(Frame::class, $this->core->last()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/DriverTest.php
tests/Unit/Drivers/Gd/DriverTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd; use Generator; use Intervention\Image\Analyzers\WidthAnalyzer as GenericWidthAnalyzer; use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder; use Intervention\Image\Decoders\FilePathImageDecoder as GenericFilePathImageDecoder; use Intervention\Image\Drivers\Gd\Analyzers\WidthAnalyzer; use Intervention\Image\Drivers\Gd\Decoders\FilePathImageDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Encoders\PngEncoder; use Intervention\Image\Drivers\Gd\Modifiers\ResizeModifier; use Intervention\Image\Encoders\PngEncoder as GenericPngEncoder; use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\FileExtension; use Intervention\Image\Format; use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorProcessorInterface; use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\SpecializableInterface; use Intervention\Image\MediaType; use Intervention\Image\Modifiers\ResizeModifier as GenericResizeModifier; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('gd')] #[CoversClass(Driver::class)] final class DriverTest extends BaseTestCase { protected Driver $driver; protected function setUp(): void { $this->driver = new Driver(); } public function testId(): void { $this->assertEquals('GD', $this->driver->id()); } public function testCreateImage(): void { $image = $this->driver->createImage(3, 2); $this->assertInstanceOf(ImageInterface::class, $image); $this->assertEquals(3, $image->width()); $this->assertEquals(2, $image->height()); } public function testCreateAnimation(): void { $image = $this->driver->createAnimation(function ($animation): void { $animation->add($this->getTestResourcePath('red.gif'), .25); $animation->add($this->getTestResourcePath('green.gif'), .25); })->setLoops(5); $this->assertInstanceOf(ImageInterface::class, $image); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $this->assertEquals(5, $image->loops()); $this->assertEquals(2, $image->count()); } public function testHandleInputImage(): void { $result = $this->driver->handleInput($this->getTestResourcePath('test.jpg')); $this->assertInstanceOf(ImageInterface::class, $result); } public function testHandleInputColor(): void { $result = $this->driver->handleInput('ffffff'); $this->assertInstanceOf(ColorInterface::class, $result); } public function testHandleInputObjects(): void { $result = $this->driver->handleInput('ffffff', [ new HexColorDecoder() ]); $this->assertInstanceOf(ColorInterface::class, $result); } public function testHandleInputClassnames(): void { $result = $this->driver->handleInput('ffffff', [ HexColorDecoder::class ]); $this->assertInstanceOf(ColorInterface::class, $result); } public function testColorProcessor(): void { $result = $this->driver->colorProcessor(new Colorspace()); $this->assertInstanceOf(ColorProcessorInterface::class, $result); } #[DataProvider('supportsDataProvider')] public function testSupports(bool $result, mixed $identifier): void { $this->assertEquals($result, $this->driver->supports($identifier)); } public static function supportsDataProvider(): Generator { yield [true, Format::JPEG]; yield [true, MediaType::IMAGE_JPEG]; yield [true, MediaType::IMAGE_JPG]; yield [true, FileExtension::JPG]; yield [true, FileExtension::JPEG]; yield [true, 'jpg']; yield [true, 'jpeg']; yield [true, 'image/jpg']; yield [true, 'image/jpeg']; yield [true, Format::WEBP]; yield [true, MediaType::IMAGE_WEBP]; yield [true, MediaType::IMAGE_X_WEBP]; yield [true, FileExtension::WEBP]; yield [true, 'webp']; yield [true, 'image/webp']; yield [true, 'image/x-webp']; yield [true, Format::GIF]; yield [true, MediaType::IMAGE_GIF]; yield [true, FileExtension::GIF]; yield [true, 'gif']; yield [true, 'image/gif']; yield [true, Format::PNG]; yield [true, MediaType::IMAGE_PNG]; yield [true, MediaType::IMAGE_X_PNG]; yield [true, FileExtension::PNG]; yield [true, 'png']; yield [true, 'image/png']; yield [true, 'image/x-png']; yield [true, Format::AVIF]; yield [true, MediaType::IMAGE_AVIF]; yield [true, MediaType::IMAGE_X_AVIF]; yield [true, FileExtension::AVIF]; yield [true, 'avif']; yield [true, 'image/avif']; yield [true, 'image/x-avif']; yield [true, Format::BMP]; yield [true, FileExtension::BMP]; yield [true, MediaType::IMAGE_BMP]; yield [true, MediaType::IMAGE_MS_BMP]; yield [true, MediaType::IMAGE_X_BITMAP]; yield [true, MediaType::IMAGE_X_BMP]; yield [true, MediaType::IMAGE_X_MS_BMP]; yield [true, MediaType::IMAGE_X_WINDOWS_BMP]; yield [true, MediaType::IMAGE_X_WIN_BITMAP]; yield [true, MediaType::IMAGE_X_XBITMAP]; yield [true, 'bmp']; yield [true, 'image/bmp']; yield [true, 'image/ms-bmp']; yield [true, 'image/x-bitmap']; yield [true, 'image/x-bmp']; yield [true, 'image/x-ms-bmp']; yield [true, 'image/x-windows-bmp']; yield [true, 'image/x-win-bitmap']; yield [true, 'image/x-xbitmap']; yield [false, Format::TIFF]; yield [false, MediaType::IMAGE_TIFF]; yield [false, FileExtension::TIFF]; yield [false, FileExtension::TIF]; yield [false, 'tif']; yield [false, 'tiff']; yield [false, 'image/tiff']; yield [false, Format::JP2]; yield [false, MediaType::IMAGE_JP2]; yield [false, MediaType::IMAGE_JPX]; yield [false, MediaType::IMAGE_JPM]; yield [false, FileExtension::TIFF]; yield [false, FileExtension::TIF]; yield [false, FileExtension::JP2]; yield [false, FileExtension::J2K]; yield [false, FileExtension::JPF]; yield [false, FileExtension::JPM]; yield [false, FileExtension::JPG2]; yield [false, FileExtension::J2C]; yield [false, FileExtension::JPC]; yield [false, FileExtension::JPX]; yield [false, 'jp2']; yield [false, 'j2k']; yield [false, 'jpf']; yield [false, 'jpm']; yield [false, 'jpg2']; yield [false, 'j2c']; yield [false, 'jpc']; yield [false, 'jpx']; yield [false, Format::HEIC]; yield [false, MediaType::IMAGE_HEIC]; yield [false, MediaType::IMAGE_HEIF]; yield [false, FileExtension::HEIC]; yield [false, FileExtension::HEIF]; yield [false, 'heic']; yield [false, 'heif']; yield [false, 'image/heic']; yield [false, 'image/heif']; yield [false, 'tga']; yield [false, 'image/tga']; yield [false, 'image/x-targa']; yield [false, 'foo']; yield [false, '']; } public function testVersion(): void { $this->assertTrue(is_string($this->driver->version())); } #[DataProvider('spezializeDataProvider')] public function testSpecialize(string $inputClassname, string $outputClassname): void { $this->assertInstanceOf($outputClassname, $this->driver->specialize(new $inputClassname())); } public static function spezializeDataProvider(): Generator { // specializing possible yield [GenericResizeModifier::class, ResizeModifier::class]; yield [GenericWidthAnalyzer::class, WidthAnalyzer::class]; yield [GenericPngEncoder::class, PngEncoder::class]; yield [GenericFilePathImageDecoder::class, FilePathImageDecoder::class]; // already specialized yield [ResizeModifier::class, ResizeModifier::class]; yield [WidthAnalyzer::class, WidthAnalyzer::class]; yield [PngEncoder::class, PngEncoder::class]; yield [FilePathImageDecoder::class, FilePathImageDecoder::class]; } public function testSpecializeFailure(): void { $this->expectException(NotSupportedException::class); $this->driver->specialize(new class () implements AnalyzerInterface, SpecializableInterface { protected DriverInterface $driver; public function analyze(ImageInterface $image): mixed { return true; } /** @return array<string, mixed> **/ public function specializable(): array { return []; } public function setDriver(DriverInterface $driver): SpecializableInterface { return $this; } public function driver(): DriverInterface { return $this->driver; } }); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php
tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders; use Generator; use Intervention\Image\Drivers\Gd\Encoders\PngEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Tests\GdTestCase; use Intervention\Image\Tests\Traits\CanInspectPngFormat; use PHPUnit\Framework\Attributes\DataProvider; #[RequiresPhpExtension('gd')] #[CoversClass(PngEncoder::class)] final class PngEncoderTest extends GdTestCase { use CanInspectPngFormat; public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new PngEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/png', $result); $this->assertEquals('image/png', $result->mimetype()); $this->assertFalse($this->isInterlacedPng($result)); } public function testEncodeInterlaced(): void { $image = $this->createTestImage(3, 2); $encoder = new PngEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/png', $result); $this->assertEquals('image/png', $result->mimetype()); $this->assertTrue($this->isInterlacedPng($result)); } #[DataProvider('indexedDataProvider')] public function testEncoderIndexed(ImageInterface $image, PngEncoder $encoder, string $result): void { $this->assertEquals( $result, $this->pngColorType($encoder->encode($image)), ); } public static function indexedDataProvider(): Generator { yield [ static::createTestImage(3, 2), // new new PngEncoder(indexed: false), 'truecolor-alpha', ]; yield [ static::createTestImage(3, 2), // new new PngEncoder(indexed: true), 'indexed', ]; yield [ static::readTestImage('circle.png'), // truecolor-alpha new PngEncoder(indexed: false), 'truecolor-alpha', ]; yield [ static::readTestImage('circle.png'), // indexedcolor-alpha new PngEncoder(indexed: true), 'indexed', ]; yield [ static::readTestImage('tile.png'), // indexed new PngEncoder(indexed: false), 'truecolor-alpha', ]; yield [ static::readTestImage('tile.png'), // indexed new PngEncoder(indexed: true), 'indexed', ]; yield [ static::readTestImage('test.jpg'), // jpeg new PngEncoder(indexed: false), 'truecolor-alpha', ]; yield [ static::readTestImage('test.jpg'), // jpeg new PngEncoder(indexed: true), 'indexed', ]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php
tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders; use Intervention\Image\Drivers\Gd\Encoders\BmpEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(BmpEncoder::class)] final class BmpEncoderTest extends GdTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new BmpEncoder(); $result = $encoder->encode($image); $this->assertMediaType(['image/bmp', 'image/x-ms-bmp'], $result); $this->assertEquals('image/bmp', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php
tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Encoders\JpegEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; use Intervention\Image\Tests\Traits\CanDetectProgressiveJpeg; #[RequiresPhpExtension('gd')] #[CoversClass(JpegEncoder::class)] final class JpegEncoderTest extends GdTestCase { use CanDetectProgressiveJpeg; public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new JpegEncoder(75); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); $this->assertEquals('image/jpeg', $result->mimetype()); } public function testEncodeProgressive(): void { $image = $this->createTestImage(3, 2); $encoder = new JpegEncoder(progressive: true); $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); $this->assertEquals('image/jpeg', $result->mimetype()); $this->assertTrue($this->isProgressiveJpeg($result)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php
tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders; use Intervention\Image\Drivers\Gd\Encoders\WebpEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(WebpEncoder::class)] final class WebpEncoderTest extends GdTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new WebpEncoder(75); $result = $encoder->encode($image); $this->assertMediaType('image/webp', $result); $this->assertEquals('image/webp', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php
tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders; use Intervention\Image\Drivers\Gd\Encoders\AvifEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(AvifEncoder::class)] final class AvifEncoderTest extends GdTestCase { public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new AvifEncoder(10); $result = $encoder->encode($image); $this->assertMediaType('image/avif', $result); $this->assertEquals('image/avif', $result->mimetype()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php
tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders; use Intervention\Gif\Decoder; use Intervention\Image\Drivers\Gd\Encoders\GifEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(GifEncoder::class)] final class GifEncoderTest extends GdTestCase { public function testEncode(): void { $image = $this->createTestAnimation(); $encoder = new GifEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); $this->assertEquals('image/gif', $result->mimetype()); $this->assertFalse( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); } public function testEncodeInterlaced(): void { $image = $this->createTestImage(3, 2); $encoder = new GifEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); $this->assertEquals('image/gif', $result->mimetype()); $this->assertTrue( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); } public function testEncodeInterlacedAnimation(): void { $image = $this->createTestAnimation(); $encoder = new GifEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); $this->assertEquals('image/gif', $result->mimetype()); $this->assertTrue( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/DataUriImageDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/DataUriImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Gd\Decoders\DataUriImageDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; use stdClass; #[RequiresPhpExtension('gd')] #[CoversClass(DataUriImageDecoder::class)] final class DataUriImageDecoderTest extends BaseTestCase { protected DataUriImageDecoder $decoder; protected function setUp(): void { $this->decoder = new DataUriImageDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecode(): void { $result = $this->decoder->decode( sprintf('data:image/jpeg;base64,%s', base64_encode($this->getTestResourceData('blue.gif'))) ); $this->assertInstanceOf(Image::class, $result); } public function testDecoderNonString(): void { $this->expectException(DecoderException::class); $this->decoder->decode(new stdClass()); } public function testDecoderInvalid(): void { $this->expectException(DecoderException::class); $this->decoder->decode('invalid'); } public function testDecoderNonImage(): void { $this->expectException(DecoderException::class); $this->decoder->decode('data:text/plain;charset=utf-8,test'); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/SplFileInfoImageDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/SplFileInfoImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Gd\Decoders\SplFileInfoImageDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; use SplFileInfo; #[RequiresPhpExtension('gd')] #[CoversClass(SplFileInfoImageDecoder::class)] final class SplFileInfoImageDecoderTest extends BaseTestCase { public function testDecode(): void { $decoder = new SplFileInfoImageDecoder(); $decoder->setDriver(new Driver()); $result = $decoder->decode( new SplFileInfo($this->getTestResourcePath('blue.gif')) ); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/NativeObjectDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/NativeObjectDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Gd\Decoders\NativeObjectDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(NativeObjectDecoder::class)] final class NativeObjectDecoderTest extends BaseTestCase { protected NativeObjectDecoder $decoder; protected function setUp(): void { $this->decoder = new NativeObjectDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecode(): void { $result = $this->decoder->decode( imagecreatetruecolor(3, 2) ); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Gd\Decoders\FilePathImageDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\DataProvider; #[RequiresPhpExtension('gd')] #[CoversClass(FilePathImageDecoder::class)] final class FilePathImageDecoderTest extends BaseTestCase { protected FilePathImageDecoder $decoder; protected function setUp(): void { $this->decoder = new FilePathImageDecoder(); $this->decoder->setDriver(new Driver()); } #[DataProvider('validFormatPathsProvider')] public function testDecode(string $path, bool $result): void { if ($result === false) { $this->expectException(DecoderException::class); } $result = $this->decoder->decode($path); if ($result === true) { $this->assertInstanceOf(Image::class, $result); } } public static function validFormatPathsProvider(): Generator { yield [self::getTestResourcePath('cats.gif'), true]; yield [self::getTestResourcePath('animation.gif'), true]; yield [self::getTestResourcePath('red.gif'), true]; yield [self::getTestResourcePath('green.gif'), true]; yield [self::getTestResourcePath('blue.gif'), true]; yield [self::getTestResourcePath('gradient.bmp'), true]; yield [self::getTestResourcePath('circle.png'), true]; yield ['no-path', false]; yield [str_repeat('x', PHP_MAXPATHLEN + 1), false]; } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/FilePointerImageDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/FilePointerImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Gd\Decoders\FilePointerImageDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Image; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(FilePointerImageDecoder::class)] final class FilePointerImageDecoderTest extends GdTestCase { public function testDecode(): void { $decoder = new FilePointerImageDecoder(); $decoder->setDriver(new Driver()); $fp = fopen($this->getTestResourcePath('test.jpg'), 'r'); $result = $decoder->decode($fp); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/AbstractDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/AbstractDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use Intervention\Image\Drivers\Gd\Decoders\AbstractDecoder; use Intervention\Image\MediaType; use Intervention\Image\Tests\BaseTestCase; use Mockery; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('gd')] #[CoversClass(AbstractDecoder::class)] final class AbstractDecoderTest extends BaseTestCase { public function testGetMediaTypeFromFilePath(): void { $decoder = Mockery::mock(AbstractDecoder::class)->makePartial(); $this->assertEquals( MediaType::IMAGE_JPEG, $decoder->getMediaTypeByFilePath($this->getTestResourcePath('test.jpg')) ); } public function testGetMediaTypeFromFileBinary(): void { $decoder = Mockery::mock(AbstractDecoder::class)->makePartial(); $this->assertEquals( MediaType::IMAGE_JPEG, $decoder->getMediaTypeByBinary($this->getTestResourceData('test.jpg')), ); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use Intervention\Image\Drivers\Gd\Decoders\EncodedImageObjectDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\EncodedImage; use Intervention\Image\Image; use Intervention\Image\Tests\ImagickTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('gd')] #[CoversClass(EncodedImageObjectDecoder::class)] class EncodedImageObjectDecoderTest extends ImagickTestCase { protected EncodedImageObjectDecoder $decoder; protected function setUp(): void { $this->decoder = new EncodedImageObjectDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecode(): void { $result = $this->decoder->decode(new EncodedImage($this->getTestResourceData())); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/ImageObjectDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/ImageObjectDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Decoders\ImageObjectDecoder; use Intervention\Image\Image; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(ImageObjectDecoder::class)] final class ImageObjectDecoderTest extends GdTestCase { public function testDecode(): void { $decoder = new ImageObjectDecoder(); $result = $decoder->decode($this->readTestImage('blue.gif')); $this->assertInstanceOf(Image::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/Base64ImageDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/Base64ImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Gd\Decoders\Base64ImageDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(Base64ImageDecoder::class)] final class Base64ImageDecoderTest extends BaseTestCase { protected Base64ImageDecoder $decoder; protected function setUp(): void { $this->decoder = new Base64ImageDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecode(): void { $result = $this->decoder->decode( base64_encode($this->getTestResourceData('blue.gif')) ); $this->assertInstanceOf(Image::class, $result); } public function testDecoderInvalid(): void { $this->expectException(DecoderException::class); $this->decoder->decode('test'); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Decoders/BinaryImageDecoderTest.php
tests/Unit/Drivers/Gd/Decoders/BinaryImageDecoderTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Gd\Decoders\BinaryImageDecoder; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Image; use Intervention\Image\Tests\BaseTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(BinaryImageDecoder::class)] final class BinaryImageDecoderTest extends BaseTestCase { protected BinaryImageDecoder $decoder; protected function setUp(): void { $this->decoder = new BinaryImageDecoder(); $this->decoder->setDriver(new Driver()); } public function testDecodePng(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('tile.png'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $this->assertCount(1, $image); } public function testDecodeGif(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('red.gif'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $this->assertCount(1, $image); } public function testDecodeAnimatedGif(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('cats.gif'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(75, $image->width()); $this->assertEquals(50, $image->height()); $this->assertCount(4, $image); } public function testDecodeJpegWithExif(): void { $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('exif.jpg'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $this->assertCount(1, $image); $this->assertEquals('Oliver Vogel', $image->exif('IFD0.Artist')); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php
tests/Unit/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Analyzers; use Intervention\Image\Drivers\Gd\Analyzers\PixelColorAnalyzer; use Intervention\Image\Drivers\Gd\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(PixelColorAnalyzer::class)] final class PixelColorAnalyzerTest extends GdTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new PixelColorAnalyzer(0, 0); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(ColorInterface::class, $result); $this->assertEquals('b4e000', $result->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Analyzers/HeightAnalyzerTest.php
tests/Unit/Drivers/Gd/Analyzers/HeightAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Analyzers; use Intervention\Image\Drivers\Gd\Analyzers\HeightAnalyzer; use Intervention\Image\Drivers\Gd\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(HeightAnalyzer::class)] final class HeightAnalyzerTest extends GdTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new HeightAnalyzer(); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertEquals(16, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Analyzers/PixelColorsAnalyzerTest.php
tests/Unit/Drivers/Gd/Analyzers/PixelColorsAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Analyzers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Collection; use Intervention\Image\Drivers\Gd\Analyzers\PixelColorsAnalyzer; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(PixelColorsAnalyzer::class)] final class PixelColorsAnalyzerTest extends GdTestCase { public function testAnalyzeAnimated(): void { $image = $this->readTestImage('animation.gif'); $analyzer = new PixelColorsAnalyzer(0, 0); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(Collection::class, $result); $colors = array_map(fn(ColorInterface $color) => $color->toHex(), $result->toArray()); $this->assertEquals($colors, ["394b63", "394b63", "394b63", "ffa601", "ffa601", "ffa601", "ffa601", "394b63"]); } public function testAnalyzeNonAnimated(): void { $image = $this->readTestImage('tile.png'); $analyzer = new PixelColorsAnalyzer(0, 0); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(Collection::class, $result); $this->assertInstanceOf(ColorInterface::class, $result->first()); $this->assertEquals('b4e000', $result->first()->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php
tests/Unit/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Analyzers; use Intervention\Image\Drivers\Gd\Analyzers\ResolutionAnalyzer; use Intervention\Image\Drivers\Gd\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Resolution; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(ResolutionAnalyzer::class)] final class ResolutionAnalyzerTest extends GdTestCase { public function testAnalyze(): void { $image = $this->readTestImage('300dpi.png'); $analyzer = new ResolutionAnalyzer(); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(Resolution::class, $result); $this->assertEquals(300, $result->perInch()->x()); $this->assertEquals(300, $result->perInch()->y()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php
tests/Unit/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Analyzers; use Intervention\Image\Drivers\Gd\Analyzers\ColorspaceAnalyzer; use Intervention\Image\Drivers\Gd\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(ColorspaceAnalyzer::class)] final class ColorspaceAnalyzerTest extends GdTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new ColorspaceAnalyzer(); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertInstanceOf(ColorspaceInterface::class, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Analyzers/WidthAnalyzerTest.php
tests/Unit/Drivers/Gd/Analyzers/WidthAnalyzerTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Analyzers; use Intervention\Image\Drivers\Gd\Analyzers\WidthAnalyzer; use Intervention\Image\Drivers\Gd\Driver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(WidthAnalyzer::class)] final class WidthAnalyzerTest extends GdTestCase { public function testAnalyze(): void { $image = $this->readTestImage('tile.png'); $analyzer = new WidthAnalyzer(); $analyzer->setDriver(new Driver()); $result = $analyzer->analyze($image); $this->assertEquals(16, $result); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/SharpenModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/SharpenModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\SharpenModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\SharpenModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\SharpenModifier::class)] final class SharpenModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('60ab96', $image->pickColor(15, 14)->toHex()); $image->modify(new SharpenModifier(10)); $this->assertEquals('4daba7', $image->pickColor(15, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/DrawLineModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/DrawLineModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawLineModifier; use Intervention\Image\Geometry\Line; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\DrawLineModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\DrawLineModifier::class)] final class DrawLineModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $line = new Line(new Point(0, 0), new Point(10, 0), 4); $line->setBackgroundColor('b53517'); $image->modify(new DrawLineModifier($line)); $this->assertEquals('b53517', $image->pickColor(0, 0)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Exceptions\InputException; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Modifiers\QuantizeColorsModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\QuantizeColorsModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\QuantizeColorsModifier::class)] final class QuantizeColorsModifierTest extends GdTestCase { public function testColorChange(): void { $image = $this->readTestImage('gradient.bmp'); $this->assertColorCount(15, $image); $image->modify(new QuantizeColorsModifier(4)); $this->assertColorCount(4, $image); } public function testNoColorReduction(): void { $image = $this->readTestImage('gradient.bmp'); $this->assertColorCount(15, $image); $image->modify(new QuantizeColorsModifier(150)); $this->assertColorCount(15, $image); } public function testInvalidColorInput(): void { $image = $this->readTestImage('gradient.bmp'); $this->expectException(InputException::class); $image->modify(new QuantizeColorsModifier(0)); } private function assertColorCount(int $count, ImageInterface $image): void { $colors = []; $width = $image->width(); $height = $image->height(); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $rgb = imagecolorat($image->core()->native(), $x, $y); $color = imagecolorsforindex($image->core()->native(), $rgb); $color = implode('-', $color); $colors[$color] = $color; } } $this->assertEquals(count($colors), $count); } public function testVerifyColorValueAfterQuantization(): void { $image = $this->createTestImage(3, 2)->fill('f00'); $image->modify(new QuantizeColorsModifier(1)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1), 4); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/CoverModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/CoverModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\CoverModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\CoverModifier::class)] final class CoverModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals(640, $image->width()); $this->assertEquals(480, $image->height()); $image->modify(new CoverModifier(100, 100, 'center')); $this->assertEquals(100, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90)); $this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70)); $this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52)); $this->assertTransparency($image->pickColor(90, 30)); } public function testModifyOddSize(): void { $image = $this->createTestImage(375, 250); $image->modify(new CoverModifier(240, 90, 'center')); $this->assertEquals(240, $image->width()); $this->assertEquals(90, $image->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/InvertModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/InvertModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\InvertModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\InvertModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\InvertModifier::class)] final class InvertModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex()); $image->modify(new InvertModifier()); $this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex()); $this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/DrawRectangleModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/DrawRectangleModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawRectangleModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\DrawRectangleModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\DrawRectangleModifier::class)] final class DrawRectangleModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $rectangle = new Rectangle(300, 200, new Point(14, 14)); $rectangle->setBackgroundColor('ffffff'); $image->modify(new DrawRectangleModifier($rectangle)); $this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasRelativeModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasRelativeModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ResizeCanvasRelativeModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\ResizeCanvasRelativeModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\ResizeCanvasRelativeModifier::class)] final class ResizeCanvasRelativeModifierTest extends GdTestCase { public function testModify(): void { $image = $this->createTestImage(1, 1); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center')); $this->assertEquals(3, $image->width()); $this->assertEquals(3, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); } public function testModifyWithTransparency(): void { $image = $this->readTestImage('tile.png'); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center')); $this->assertEquals(18, $image->width()); $this->assertEquals(18, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1)); $this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2)); $this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17)); $this->assertTransparency($image->pickColor(12, 1)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/PadModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/PadModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\PadModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\PadModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\PadModifier::class)] final class PadModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('blue.gif'); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $image->modify(new PadModifier(30, 20, 'f00')); $this->assertEquals(30, $image->width()); $this->assertEquals(20, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 19)); $this->assertColor(255, 0, 0, 255, $image->pickColor(29, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(29, 19)); $this->assertColor(255, 0, 0, 255, $image->pickColor(6, 2)); $this->assertColor(255, 0, 0, 255, $image->pickColor(7, 1)); $this->assertColor(255, 0, 0, 255, $image->pickColor(6, 17)); $this->assertColor(255, 0, 0, 255, $image->pickColor(7, 18)); $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 1)); $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 2)); $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 17)); $this->assertColor(255, 0, 0, 255, $image->pickColor(23, 18)); $this->assertColor(100, 100, 255, 255, $image->pickColor(7, 2)); $this->assertColor(100, 100, 255, 255, $image->pickColor(22, 2)); $this->assertColor(100, 100, 255, 255, $image->pickColor(7, 17)); $this->assertColor(100, 100, 255, 255, $image->pickColor(22, 17)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/TextModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/TextModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Modifiers\TextModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Interfaces\ColorInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; use Intervention\Image\Typography\Font; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\TextModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\TextModifier::class)] final class TextModifierTest extends GdTestCase { public function testTextColor(): void { $font = (new Font())->setColor('ff0055'); $modifier = new class ('test', new Point(), $font) extends TextModifier { public function test(): ColorInterface { return $this->textColor(); } }; $modifier->setDriver(new Driver()); $this->assertInstanceOf(ColorInterface::class, $modifier->test()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/RemoveAnimationModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/RemoveAnimationModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Exceptions\InputException; use Intervention\Image\Modifiers\RemoveAnimationModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\RemoveAnimationModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\RemoveAnimationModifier::class)] final class RemoveAnimationModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('animation.gif'); $this->assertEquals(8, count($image)); $result = $image->modify(new RemoveAnimationModifier(2)); $this->assertEquals(1, count($image)); $this->assertEquals(1, count($result)); } public function testApplyPercent(): void { $image = $this->readTestImage('animation.gif'); $this->assertEquals(8, count($image)); $result = $image->modify(new RemoveAnimationModifier('20%')); $this->assertEquals(1, count($image)); $this->assertEquals(1, count($result)); } public function testApplyNonAnimated(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals(1, count($image)); $result = $image->modify(new RemoveAnimationModifier()); $this->assertEquals(1, count($image)); $this->assertEquals(1, count($result)); } public function testApplyInvalid(): void { $image = $this->readTestImage('animation.gif'); $this->expectException(InputException::class); $image->modify(new RemoveAnimationModifier('test')); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/ContainModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/ContainModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ContainModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\ContainModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\ContainModifier::class)] final class ContainModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals(640, $image->width()); $this->assertEquals(480, $image->height()); $image->modify(new ContainModifier(200, 100, 'ff0')); $this->assertEquals(200, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertTransparency($image->pickColor(140, 10)); $this->assertColor(255, 255, 0, 255, $image->pickColor(175, 10)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/DrawPixelModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/DrawPixelModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawPixelModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\DrawPixelModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\DrawPixelModifier::class)] final class DrawPixelModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new DrawPixelModifier(new Point(14, 14), 'ffffff')); $this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/CropModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/CropModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\CropModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\CropModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\CropModifier::class)] final class CropModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $image = $image->modify(new CropModifier(200, 200, 0, 0, 'ffffff', 'bottom-right')); $this->assertEquals(200, $image->width()); $this->assertEquals(200, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(5, 5)); $this->assertColor(255, 0, 0, 255, $image->pickColor(100, 100)); $this->assertColor(255, 0, 0, 255, $image->pickColor(190, 190)); } public function testModifyExtend(): void { $image = $this->readTestImage('blocks.png'); $image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000', 'top-left')); $this->assertEquals(800, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(9, 9)); $this->assertColor(0, 0, 255, 255, $image->pickColor(16, 16)); $this->assertColor(0, 0, 255, 255, $image->pickColor(445, 16)); $this->assertTransparency($image->pickColor(460, 16)); } public function testModifySinglePixel(): void { $image = $this->createTestImage(1, 1); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $image->modify(new CropModifier(3, 3, 0, 0, 'ff0', 'center')); $this->assertEquals(3, $image->width()); $this->assertEquals(3, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); } public function testModifyKeepsResolution(): void { $image = $this->readTestImage('300dpi.png'); $this->assertEquals(300, round($image->resolution()->perInch()->x())); $image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000')); $this->assertEquals(300, round($image->resolution()->perInch()->x())); } public function testHalfTransparent(): void { $image = $this->createTestImage(16, 16); $image->modify(new CropModifier(32, 32, 0, 0, '00f5', 'center')); $this->assertEquals(32, $image->width()); $this->assertEquals(32, $image->height()); $this->assertColor(0, 0, 255, 85, $image->pickColor(5, 5)); $this->assertColor(0, 0, 255, 85, $image->pickColor(16, 5)); $this->assertColor(0, 0, 255, 85, $image->pickColor(30, 5)); $this->assertColor(0, 0, 255, 85, $image->pickColor(5, 16)); $this->assertColor(255, 0, 0, 255, $image->pickColor(16, 16)); $this->assertColor(0, 0, 255, 85, $image->pickColor(30, 16)); $this->assertColor(0, 0, 255, 85, $image->pickColor(5, 30)); $this->assertColor(0, 0, 255, 85, $image->pickColor(16, 30)); $this->assertColor(0, 0, 255, 85, $image->pickColor(30, 30)); } public function testMergeTransparentBackgrounds(): void { $image = $this->createTestImage(1, 1)->fill('f00'); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $image->modify(new CropModifier(3, 3, 0, 0, '00f7', 'center')); $this->assertEquals(3, $image->width()); $this->assertEquals(3, $image->height()); $this->assertColor(0, 0, 255, 119, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); $this->assertColor(0, 0, 255, 119, $image->pickColor(2, 2)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/ColorizeModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/ColorizeModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ColorizeModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\ColorizeModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\ColorizeModifier::class)] final class ColorizeModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('tile.png'); $image = $image->modify(new ColorizeModifier(100, -100, -100)); $this->assertColor(255, 0, 0, 255, $image->pickColor(5, 5)); $this->assertColor(255, 0, 0, 255, $image->pickColor(15, 15)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/ResolutionModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/ResolutionModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ResolutionModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\ResolutionModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\ResolutionModifier::class)] final class ResolutionModifierTest extends GdTestCase { public function testResolutionChange(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals(72.0, $image->resolution()->x()); $this->assertEquals(72.0, $image->resolution()->y()); $image->modify(new ResolutionModifier(1, 2)); $this->assertEquals(1.0, $image->resolution()->x()); $this->assertEquals(2.0, $image->resolution()->y()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/BrightnessModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/BrightnessModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\BrightnessModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\BrightnessModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\BrightnessModifier::class)] final class BrightnessModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new BrightnessModifier(30)); $this->assertEquals('4cfaff', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/DrawPolygonModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/DrawPolygonModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawPolygonModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Polygon; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\DrawPixelModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\DrawPixelModifier::class)] final class DrawPolygonModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $drawable = new Polygon([new Point(0, 0), new Point(15, 15), new Point(20, 20)]); $drawable->setBackgroundColor('b53717'); $image->modify(new DrawPolygonModifier($drawable)); $this->assertEquals('b53717', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/CoverDownModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/CoverDownModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use Intervention\Image\Drivers\Gd\Modifiers\CoverDownModifier; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\CoverModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\CoverModifier::class)] final class CoverDownModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals(640, $image->width()); $this->assertEquals(480, $image->height()); $image->modify(new CoverDownModifier(100, 100, 'center')); $this->assertEquals(100, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90)); $this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70)); $this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52)); $this->assertTransparency($image->pickColor(90, 30)); } public function testModifyOddSize(): void { $image = $this->createTestImage(375, 250); $image->modify(new CoverDownModifier(240, 90, 'center')); $this->assertEquals(240, $image->width()); $this->assertEquals(90, $image->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/PixelateModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/PixelateModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\PixelateModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\PixelateModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\PixelateModifier::class)] final class PixelateModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('trim.png'); $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->pickColor(0, 0)->toHex()); $this->assertEquals('6aaa8b', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/DrawBezierModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/DrawBezierModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawBezierModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Bezier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\DrawPixelModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\DrawPixelModifier::class)] final class DrawBezierModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $drawable = new Bezier([ new Point(0, 0), new Point(15, 0), new Point(15, 15), new Point(0, 15) ]); $drawable->setBackgroundColor('b53717'); $image->modify(new DrawBezierModifier($drawable)); $this->assertEquals('b53717', $image->pickColor(5, 5)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/BlurModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/BlurModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\BlurModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\BlurModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\BlurModifier::class)] final class BlurModifierTest extends GdTestCase { public function testColorChange(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new BlurModifier(30)); $this->assertEquals('4fa68d', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/ResizeModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/ResizeModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ResizeModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\ResizeModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\ResizeModifier::class)] final class ResizeModifierTest extends GdTestCase { public function testModify(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals(640, $image->width()); $this->assertEquals(480, $image->height()); $image->modify(new ResizeModifier(200, 100)); $this->assertEquals(200, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 0, 0, 255, $image->pickColor(150, 70)); $this->assertColor(0, 255, 0, 255, $image->pickColor(125, 70)); $this->assertColor(0, 0, 255, 255, $image->pickColor(130, 54)); $this->assertTransparency($image->pickColor(170, 30)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ResizeCanvasModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\ResizeCanvasModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\ResizeCanvasModifier::class)] final class ResizeCanvasModifierTest extends GdTestCase { public function testModify(): void { $image = $this->createTestImage(1, 1); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $image->modify(new ResizeCanvasModifier(3, 3, 'ff0', 'center')); $this->assertEquals(3, $image->width()); $this->assertEquals(3, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); } public function testModifyWithTransparency(): void { $image = $this->readTestImage('tile.png'); $this->assertEquals(16, $image->width()); $this->assertEquals(16, $image->height()); $image->modify(new ResizeCanvasModifier(18, 18, 'ff0', 'center')); $this->assertEquals(18, $image->width()); $this->assertEquals(18, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1)); $this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2)); $this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17)); $this->assertTransparency($image->pickColor(12, 1)); $image = $this->createTestImage(16, 16); $image->modify(new ResizeCanvasModifier(32, 32, '00f5', 'center')); $this->assertEquals(32, $image->width()); $this->assertEquals(32, $image->height()); $this->assertColor(0, 0, 255, 85, $image->pickColor(5, 5)); $this->assertColor(0, 0, 255, 85, $image->pickColor(16, 5)); $this->assertColor(0, 0, 255, 85, $image->pickColor(30, 5)); $this->assertColor(0, 0, 255, 85, $image->pickColor(5, 16)); $this->assertColor(255, 0, 0, 255, $image->pickColor(16, 16)); $this->assertColor(0, 0, 255, 85, $image->pickColor(30, 16)); $this->assertColor(0, 0, 255, 85, $image->pickColor(5, 30)); $this->assertColor(0, 0, 255, 85, $image->pickColor(16, 30)); $this->assertColor(0, 0, 255, 85, $image->pickColor(30, 30)); } public function testModifyEdge(): void { $image = $this->createTestImage(1, 1); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom')); $this->assertEquals(1, $image->width()); $this->assertEquals(2, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 1)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/DrawEllipseModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/DrawEllipseModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\DrawEllipseModifier; use Intervention\Image\Geometry\Ellipse; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\DrawEllipseModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\DrawEllipseModifier::class)] final class DrawEllipseModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $drawable = new Ellipse(10, 10, new Point(14, 14)); $drawable->setBackgroundColor('b53717'); $image->modify(new DrawEllipseModifier($drawable)); $this->assertEquals('b53717', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/FillModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/FillModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Modifiers\FillModifier; use Intervention\Image\Geometry\Point; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\FillModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\FillModifier::class)] final class FillModifierTest extends GdTestCase { public function testFloodFillColor(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); $this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex()); $image->modify(new FillModifier(new Color(204, 204, 204), new Point(540, 400))); $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); $this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex()); } public function testFillAllColor(): void { $image = $this->readTestImage('blocks.png'); $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); $this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex()); $image->modify(new FillModifier(new Color(204, 204, 204))); $this->assertEquals('cccccc', $image->pickColor(420, 270)->toHex()); $this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/ContrastModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/ContrastModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\ContrastModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\ContrastModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\ContrastModifier::class)] final class ContrastModifierTest extends GdTestCase { public function testApply(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $image->modify(new ContrastModifier(30)); $this->assertEquals('00ceff', $image->pickColor(14, 14)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/GreyscaleModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/GreyscaleModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\GreyscaleModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\GreyscaleModifier::class)] final class GreyscaleModifierTest extends GdTestCase { public function testColorChange(): void { $image = $this->readTestImage('trim.png'); $this->assertFalse($image->pickColor(0, 0)->isGreyscale()); $image->modify(new GreyscaleModifier()); $this->assertTrue($image->pickColor(0, 0)->isGreyscale()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/PlaceModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/PlaceModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\PlaceModifier; use Intervention\Image\Tests\GdTestCase; use Intervention\Image\Drivers\Gd\Modifiers\PlaceModifier as PlaceModifierGd; #[RequiresPhpExtension('gd')] #[CoversClass(PlaceModifier::class)] #[CoversClass(PlaceModifierGd::class)] final class PlaceModifierTest extends GdTestCase { public function testColorChange(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals('febc44', $image->pickColor(300, 25)->toHex()); $image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0)); $this->assertEquals('32250d', $image->pickColor(300, 25)->toHex()); } public function testColorChangeOpacityPng(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals('febc44', $image->pickColor(300, 25)->toHex()); $image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0, 50)); $this->assertColor(152, 112, 40, 255, $image->pickColor(300, 25), tolerance: 1); $this->assertColor(255, 202, 107, 255, $image->pickColor(274, 5), tolerance: 1); } public function testColorChangeOpacityJpeg(): void { $image = $this->createTestImage(16, 16)->fill('0000ff'); $this->assertEquals('0000ff', $image->pickColor(10, 10)->toHex()); $image->modify(new PlaceModifier($this->getTestResourcePath('exif.jpg'), opacity: 50)); $this->assertColor(127, 83, 127, 255, $image->pickColor(10, 10), tolerance: 1); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/TrimModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/TrimModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use Intervention\Image\Exceptions\NotSupportedException; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\TrimModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\TrimModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\TrimModifier::class)] final class TrimModifierTest extends GdTestCase { public function testTrim(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals(50, $image->width()); $this->assertEquals(50, $image->height()); $image->modify(new TrimModifier()); $this->assertEquals(28, $image->width()); $this->assertEquals(28, $image->height()); } public function testTrimGradient(): void { $image = $this->readTestImage('radial.png'); $this->assertEquals(50, $image->width()); $this->assertEquals(50, $image->height()); $image->modify(new TrimModifier(50)); $this->assertEquals(35, $image->width()); $this->assertEquals(35, $image->height()); } public function testTrimHighTolerance(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals(50, $image->width()); $this->assertEquals(50, $image->height()); $image->modify(new TrimModifier(1000000)); $this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->height()); $this->assertColor(255, 255, 255, 0, $image->pickColor(0, 0)); } public function testTrimAnimated(): void { $image = $this->readTestImage('animation.gif'); $this->expectException(NotSupportedException::class); $image->modify(new TrimModifier()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/RotateModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/RotateModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\RotateModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\RotateModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\RotateModifier::class)] final class RotateModifierTest extends GdTestCase { public function testRotate(): void { $image = $this->readTestImage('test.jpg'); $this->assertEquals(320, $image->width()); $this->assertEquals(240, $image->height()); $image->modify(new RotateModifier(90, 'fff')); $this->assertEquals(240, $image->width()); $this->assertEquals(320, $image->height()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/GammaModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/GammaModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\GammaModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\GammaModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\GammaModifier::class)] final class GammaModifierTest extends GdTestCase { public function testModifier(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $image->modify(new GammaModifier(2.1)); $this->assertEquals('00d5f8', $image->pickColor(0, 0)->toHex()); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Gd/Modifiers/FlipFlopModifierTest.php
tests/Unit/Drivers/Gd/Modifiers/FlipFlopModifierTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Modifiers\FlipModifier; use Intervention\Image\Modifiers\FlopModifier; use Intervention\Image\Tests\GdTestCase; #[RequiresPhpExtension('gd')] #[CoversClass(\Intervention\Image\Modifiers\FlipModifier::class)] #[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\FlipModifier::class)] final class FlipFlopModifierTest extends GdTestCase { public function testFlipImage(): void { $image = $this->readTestImage('tile.png'); $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); $image->modify(new FlipModifier()); $this->assertTransparency($image->pickColor(0, 0)); } public function testFlopImage(): void { $image = $this->readTestImage('tile.png'); $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); $image->modify(new FlopModifier()); $this->assertTransparency($image->pickColor(0, 0)); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/ImageTest.php
tests/Unit/Drivers/Imagick/ImageTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick; use Imagick; use Intervention\Image\Analyzers\WidthAnalyzer; use Intervention\Image\Collection; use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace; use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; use Intervention\Image\Drivers\Imagick\Core; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Frame; use Intervention\Image\EncodedImage; use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Exceptions\EncoderException; use Intervention\Image\Image; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ResolutionInterface; use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Origin; use Intervention\Image\Tests\ImagickTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('imagick')] #[CoversClass(Image::class)] final class ImageTest extends ImagickTestCase { protected Image $image; protected function setUp(): void { $imagick = new Imagick(); $imagick->readImage($this->getTestResourcePath('animation.gif')); $this->image = new Image( new Driver(), new Core($imagick), new Collection([ 'test' => 'foo' ]), ); } public function testClone(): void { $image = $this->readTestImage('gradient.gif'); $clone = clone $image; $this->assertEquals(16, $image->width()); $this->assertEquals(16, $clone->width()); $result = $clone->crop(4, 4); $this->assertEquals(16, $image->width()); $this->assertEquals(4, $clone->width()); $this->assertEquals(4, $result->width()); $this->assertEquals('ff0000', $image->pickColor(0, 0)->toHex()); $this->assertTransparency($image->pickColor(1, 0)); $this->assertEquals('ff0000', $clone->pickColor(0, 0)->toHex()); $this->assertTransparency($clone->pickColor(1, 0)); } public function testDriver(): void { $this->assertInstanceOf(Driver::class, $this->image->driver()); } public function testCore(): void { $this->assertInstanceOf(Core::class, $this->image->core()); } public function testCount(): void { $this->assertEquals(8, $this->image->count()); } public function testIteration(): void { foreach ($this->image as $frame) { $this->assertInstanceOf(Frame::class, $frame); } } public function testIsAnimated(): void { $this->assertTrue($this->image->isAnimated()); } public function testSetGetLoops(): void { $this->assertEquals(3, $this->image->loops()); $result = $this->image->setLoops(10); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals(10, $this->image->loops()); } public function testSetGetOrigin(): void { $origin = $this->image->origin(); $this->assertInstanceOf(Origin::class, $origin); $this->image->setOrigin(new Origin('test1', 'test2')); $this->assertInstanceOf(Origin::class, $this->image->origin()); $this->assertEquals('test1', $this->image->origin()->mimetype()); $this->assertEquals('test2', $this->image->origin()->filePath()); } public function testRemoveAnimation(): void { $this->assertTrue($this->image->isAnimated()); $result = $this->image->removeAnimation(); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertFalse($this->image->isAnimated()); } public function testSliceAnimation(): void { $this->assertEquals(8, $this->image->count()); $result = $this->image->sliceAnimation(0, 2); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals(2, $this->image->count()); } public function testExif(): void { $this->assertInstanceOf(Collection::class, $this->image->exif()); $this->assertEquals('foo', $this->image->exif('test')); } public function testModify(): void { $result = $this->image->modify(new GreyscaleModifier()); $this->assertInstanceOf(Image::class, $result); } public function testAnalyze(): void { $result = $this->image->analyze(new WidthAnalyzer()); $this->assertEquals(20, $result); } public function testEncode(): void { $result = $this->image->encode(new PngEncoder()); $this->assertInstanceOf(EncodedImage::class, $result); } public function testAutoEncode(): void { $result = $this->readTestImage('blue.gif')->encode(); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/gif', $result); } public function testEncodeByMediaType(): void { $result = $this->readTestImage('blue.gif')->encodeByMediaType(); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/gif', $result); $result = $this->readTestImage('blue.gif')->encodeByMediaType('image/png'); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/png', $result); } public function testEncodeByExtension(): void { $result = $this->readTestImage('blue.gif')->encodeByExtension(); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/gif', $result); $result = $this->readTestImage('blue.gif')->encodeByExtension('png'); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/png', $result); } public function testEncodeByPath(): void { $result = $this->readTestImage('blue.gif')->encodeByPath(); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/gif', $result); $result = $this->readTestImage('blue.gif')->encodeByPath('foo/bar.png'); $this->assertInstanceOf(EncodedImage::class, $result); $this->assertMediaType('image/png', $result); } public function testSaveAsFormat(): void { $path = __DIR__ . '/tmp.png'; $result = $this->readTestImage('blue.gif')->save($path); $this->assertInstanceOf(Image::class, $result); $this->assertFileExists($path); $this->assertMediaType('image/png', file_get_contents($path)); unlink($path); } public function testSaveFallback(): void { $path = __DIR__ . '/tmp.unknown'; $result = $this->readTestImage('blue.gif')->save($path); $this->assertInstanceOf(Image::class, $result); $this->assertFileExists($path); $this->assertMediaType('image/gif', file_get_contents($path)); unlink($path); } public function testSaveUndeterminedPath(): void { $this->expectException(EncoderException::class); $this->createTestImage(2, 3)->save(); } public function testWidthHeightSize(): void { $this->assertEquals(20, $this->image->width()); $this->assertEquals(15, $this->image->height()); $this->assertInstanceOf(SizeInterface::class, $this->image->size()); } public function testSetGetColorspace(): void { $this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace()); $this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace()); $result = $this->image->setColorspace(CmykColorspace::class); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertInstanceOf(CmykColorspace::class, $this->image->colorspace()); } public function testSetGetResolution(): void { $resolution = $this->image->resolution(); $this->assertInstanceOf(ResolutionInterface::class, $resolution); $this->assertEquals(0, $resolution->x()); $this->assertEquals(0, $resolution->y()); $result = $this->image->setResolution(300, 300); $resolution = $this->image->resolution(); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals(300, $resolution->x()); $this->assertEquals(300, $resolution->y()); } public function testPickColor(): void { $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0)); $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0, 1)); } public function testPickColors(): void { $result = $this->image->pickColors(0, 0); $this->assertInstanceOf(Collection::class, $result); $this->assertEquals(8, $result->count()); } public function testProfile(): void { $this->expectException(ColorException::class); $this->image->profile(); } public function testReduceColors(): void { $image = $this->readTestImage(); $result = $image->reduceColors(8); $this->assertInstanceOf(ImageInterface::class, $result); } public function testSharpen(): void { $this->assertInstanceOf(Image::class, $this->image->sharpen(12)); } public function testBlendTransparencyDefault(): void { $image = $this->readTestImage('gradient.gif'); $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); $result = $image->blendTransparency(); $this->assertColor(255, 255, 255, 255, $image->pickColor(1, 0)); $this->assertColor(255, 255, 255, 255, $result->pickColor(1, 0)); } public function testBlendTransparencyArgument(): void { $image = $this->readTestImage('gradient.gif'); $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); $result = $image->blendTransparency('ff5500'); $this->assertColor(255, 85, 0, 255, $image->pickColor(1, 0)); $this->assertColor(255, 85, 0, 255, $result->pickColor(1, 0)); } public function testBlendTransparencyIgnoreTransparencyInBlendingColor(): void { $image = $this->readTestImage('gradient.gif'); $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); $result = $image->blendTransparency('ff550055'); $this->assertColor(255, 85, 0, 255, $image->pickColor(1, 0)); $this->assertColor(255, 85, 0, 255, $result->pickColor(1, 0)); } public function testToJpeg(): void { $this->assertMediaType('image/jpeg', $this->image->toJpeg()); $this->assertMediaType('image/jpeg', $this->image->toJpg()); } public function testToJpeg2000(): void { $this->assertMediaType('image/jp2', $this->image->toJpeg2000()); $this->assertMediaType('image/jp2', $this->image->toJp2()); } public function testToPng(): void { $this->assertMediaType('image/png', $this->image->toPng()); } public function testToGif(): void { $this->assertMediaType('image/gif', $this->image->toGif()); } public function testToWebp(): void { $this->assertMediaType('image/webp', $this->image->toWebp()); } public function testToBitmap(): void { $this->assertMediaTypeBitmap($this->image->toBitmap()); $this->assertMediaTypeBitmap($this->image->toBmp()); } public function testToAvif(): void { $this->assertMediaType('image/avif', $this->image->toAvif()); } public function testToTiff(): void { $this->assertMediaType('image/tiff', $this->image->toTiff()); $this->assertMediaType('image/tiff', $this->image->toTif()); } public function testToHeic(): void { $this->assertMediaType('image/heic', $this->image->toHeic()); } public function testInvert(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex()); $result = $image->invert(); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex()); $this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex()); } public function testPixelate(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $result = $image->pixelate(10); $this->assertInstanceOf(ImageInterface::class, $result); [$r, $g, $b] = $image->pickColor(0, 0)->toArray(); $this->assertEquals(0, $r); $this->assertEquals(174, $g); $this->assertEquals(240, $b); [$r, $g, $b] = $image->pickColor(14, 14)->toArray(); $this->assertEquals(107, $r); $this->assertEquals(171, $g); $this->assertEquals(140, $b); } public function testGreyscale(): void { $image = $this->readTestImage('trim.png'); $this->assertFalse($image->pickColor(0, 0)->isGreyscale()); $result = $image->greyscale(); $this->assertInstanceOf(ImageInterface::class, $result); $this->assertTrue($image->pickColor(0, 0)->isGreyscale()); } public function testBrightness(): void { $image = $this->readTestImage('trim.png'); $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); $result = $image->brightness(30); $this->assertInstanceOf(ImageInterface::class, $result); $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); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/FrameTest.php
tests/Unit/Drivers/Imagick/FrameTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Imagick; use ImagickPixel; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Frame; use Intervention\Image\Image; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Tests\BaseTestCase; #[RequiresPhpExtension('imagick')] #[CoversClass(Frame::class)] final class FrameTest extends BaseTestCase { protected function getTestFrame(): Frame { $imagick = new Imagick(); $imagick->newImage(3, 2, new ImagickPixel('red'), 'png'); $imagick->setImageDelay(125); // 1.25 seconds $imagick->setImageDispose(0); $imagick->setImagePage(3, 2, 8, 9); return new Frame($imagick); } public function testConstructor(): void { $frame = $this->getTestFrame(); $this->assertInstanceOf(Frame::class, $frame); } public function testGetSize(): void { $frame = $this->getTestFrame(); $this->assertInstanceOf(Rectangle::class, $frame->size()); } public function testSetGetDelay(): void { $frame = $this->getTestFrame(); $this->assertEquals(1.25, $frame->delay()); $result = $frame->setDelay(2.5); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(2.5, $frame->delay()); $this->assertEquals(250, $frame->native()->getImageDelay()); } public function testSetGetDispose(): void { $frame = $this->getTestFrame(); $this->assertEquals(0, $frame->dispose()); $result = $frame->setDispose(3); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(3, $frame->dispose()); } public function testSetGetOffsetLeft(): void { $frame = $this->getTestFrame(); $this->assertEquals(8, $frame->offsetLeft()); $result = $frame->setOffsetLeft(100); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(100, $frame->offsetLeft()); } public function testSetGetOffsetTop(): void { $frame = $this->getTestFrame(); $this->assertEquals(9, $frame->offsetTop()); $result = $frame->setOffsetTop(100); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(100, $frame->offsetTop()); } public function testSetGetOffset(): void { $frame = $this->getTestFrame(); $this->assertEquals(8, $frame->offsetLeft()); $this->assertEquals(9, $frame->offsetTop()); $result = $frame->setOffset(100, 200); $this->assertInstanceOf(Frame::class, $result); $this->assertEquals(100, $frame->offsetLeft()); $this->assertEquals(200, $frame->offsetTop()); } public function testToImage(): void { $frame = $this->getTestFrame(); $this->assertInstanceOf(Image::class, $frame->toImage(new Driver())); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false
Intervention/image
https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/Drivers/Imagick/ColorProcessorTest.php
tests/Unit/Drivers/Imagick/ColorProcessorTest.php
<?php declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick; use ImagickPixel; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Drivers\Imagick\ColorProcessor; use Intervention\Image\Tests\BaseTestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('imagick')] #[CoversClass(ColorProcessor::class)] final class ColorProcessorTest extends BaseTestCase { public function testColorToNative(): void { $processor = new ColorProcessor(new Colorspace()); $result = $processor->colorToNative(new Color(255, 55, 0, 255)); $this->assertInstanceOf(ImagickPixel::class, $result); } public function testNativeToColor(): void { $processor = new ColorProcessor(new Colorspace()); $processor->nativeToColor(new ImagickPixel('rgb(255, 55, 0)')); } }
php
MIT
5f6d27d9fd56312c47f347929e7ac15345c605a1
2026-01-04T15:02:42.957046Z
false