diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index be613e9..008fd67 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -56,12 +56,12 @@ jobs: runs-on: ${{ matrix.os }} strategy: - fail-fast: false + fail-fast: true matrix: laravel: [ '10', '9', '8' ] php: [ '8.2', '8.1', '8.0' ] - os: [ ubuntu-latest, windows-latest, macOS-latest ] + os: [ ubuntu-latest ] steps: - uses: actions/checkout@v3 @@ -70,7 +70,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: fileinfo, imagick + extensions: fileinfo, imagick, gd coverage: xdebug - name: Get composer cache directory for Windows diff --git a/src/Facades/Thumbhash.php b/src/Facades/Thumbhash.php index 5023982..4f4d98e 100644 --- a/src/Facades/Thumbhash.php +++ b/src/Facades/Thumbhash.php @@ -8,6 +8,9 @@ /** * @method static string encode(mixed|string|UploadedFile|Image $data) + * @method static void setDriver(string $driver) + * @method static string getDriver() + * @method static void setResizedImageMaxSize(int $imageMaxSize) */ class Thumbhash extends Facade { diff --git a/tests/LaravelTest.php b/tests/LaravelTest.php index f63fae7..6fe882f 100644 --- a/tests/LaravelTest.php +++ b/tests/LaravelTest.php @@ -46,5 +46,19 @@ public function testPackageLoaded(): void $hash, Thumbhash::encode(__DIR__ . '/assets/sunrise.jpg'), ); + + // Test GD + + Thumbhash::setDriver('gd'); + + $this->assertSame( + 'gd', + Thumbhash::getDriver() + ); + + $this->assertSame( + $hash, + Thumbhash::encode(__DIR__ . '/assets/sunrise.jpg'), + ); } } diff --git a/tests/ThumbhashTest.php b/tests/ThumbhashTest.php index af4ec78..8a61871 100644 --- a/tests/ThumbhashTest.php +++ b/tests/ThumbhashTest.php @@ -5,13 +5,9 @@ use Riajul\Thumbhash\Thumbhash; use PHPUnit\Framework\TestCase; -/** - * These tests are only Imagick compatible. - * If you use GD driver, than results will unexpected. - */ class ThumbhashTest extends TestCase { - public function testEncode(): void + public function testEncodeImagick(): void { $data = [ [ @@ -54,7 +50,7 @@ public function testEncode(): void ], ]; - $hash = new Thumbhash(); + $hash = new Thumbhash('imagick'); $this->assertSame( 'imagick', @@ -68,4 +64,62 @@ public function testEncode(): void ); } } + + public function testEncodeGd(): void + { + $data = [ + [ + 'url' => 'assets/sunrise.jpg', + 'hash' => '1QcSHQRnh493V4dIh4eXh1h4kJUI' + ], + [ + 'url' => 'assets/sunset.jpg', + 'hash' => '3PcNNYSFeXh/d3eld0iHZoZgVwh2' + ], + [ + 'url' => 'assets/field.jpg', + 'hash' => '3OcRJYB4d3h/iIeHeEh3eIhw+j3A' + ], + [ + 'url' => 'assets/fall.jpg', + 'hash' => 'HBkSHYSIeHiPiHh8eJd4eTN0EEQG' + ], + [ + 'url' => 'assets/street.jpg', + 'hash' => 'VggKDYAW6lZvdYd6d2iZh/p4GE/k' + ], + [ + 'url' => 'assets/mountain.jpg', + 'hash' => '2fcZFIB3iId/h3iJh4aIYJ2W8g' + ], + [ + 'url' => 'assets/coast.jpg', + 'hash' => 'IQgSLYZ6iHePh4h1eFeHh4dwgwg3' + ], + + // Images with transparency + [ + 'url' => 'assets/firefox.png', + 'hash' => 'YJqGPQw7sFlslqhFafSE+Q6oJ1h2iHB2Rw' + ], + [ + 'url' => 'assets/opera.png', + 'hash' => 'mYqDBQQnxnj0JoLYdN7f8JhpuDeHiHdwZw' + ], + ]; + + $hash = new Thumbhash('gd'); + + $this->assertSame( + 'gd', + $hash->getDriver(), + ); + + foreach ($data as $item) { + $this->assertSame( + $item['hash'], + $hash->encode(__DIR__ . '/' . $item['url']) + ); + } + } }