Skip to content

Commit

Permalink
Add tests for WebP images
Browse files Browse the repository at this point in the history
  • Loading branch information
ksubileau committed Feb 7, 2021
1 parent 674728b commit a3ec81d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ColorThief/Image/Adapter/GDImageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function loadFile(string $file): void
$resource = @imagecreatefrompng($file);
break;

case IMAGETYPE_WEBP:
case \IMAGETYPE_WEBP:
$resource = @imagecreatefromwebp($file);
break;

Expand Down
21 changes: 21 additions & 0 deletions tests/ColorThiefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public function provideImageDominantColor()
null,
[180, 228, 28],
],
/*
[ // WebP image
'/images/donuts_PR45.webp',
null,
[204, 187, 177],
],
*/
[ // Area targeting
'/images/vegetables_1500x995.png',
['x' => 670, 'y' => 215, 'w' => 230, 'h' => 120],
Expand Down Expand Up @@ -110,6 +117,20 @@ public function provideImageColorPalette()
[184, 228, 28],
],
],
/*
[
'/images/donuts_PR45.webp',
[
[44, 99, 88],
[212, 200, 182],
[148, 36, 46],
[185, 141, 29],
[183, 147, 89],
[175, 103, 144],
[118, 204, 192],
],
],
*/
];
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Image/Adapter/BaseImageAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public function testLoadFileGif(): IImageAdapter
return $this->baseTestLoadFile(__DIR__.'/../../images/rails_600x406.gif');
}

public function testLoadFileWebp(): IImageAdapter
{
return $this->baseTestLoadFile(__DIR__.'/../../images/donuts_PR45.webp');
}

/**
* @see Issue #13
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Image/Adapter/GDImageAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ public function testLoadFileJpgCorrupted(): IImageAdapter

return $this->baseTestLoadFile(__DIR__.'/../../images/corrupted_PR30.jpg');
}

/**
* @requires function imagecreatefromwebp
*/
public function testLoadFileWebp(): IImageAdapter
{
return parent::testLoadFileWebp();
}
}
9 changes: 9 additions & 0 deletions tests/Image/Adapter/ImagickImageAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ public function testLoadInvalidArgument(): void
// We want to check also the specific exception message.
parent::testLoadInvalidArgument();
}

public function testLoadFileWebp(): IImageAdapter
{
if (empty(Imagick::queryFormats('WEBP'))) {
$this->markTestSkipped('Imagick was not compiled with support for WebP format.');
}

return parent::testLoadFileWebp();
}
}
Binary file added tests/images/donuts_PR45.webp
Binary file not shown.

0 comments on commit a3ec81d

Please sign in to comment.