Skip to content

Commit

Permalink
tests: force use imagick.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamriajul committed Oct 31, 2023
1 parent 46e45c5 commit b6c37be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Thumbhash.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public function setDriver(string $driver): self {
return $this;
}

/**
* @return string
*/
public function getDriver(): string
{
return $this->driver;
}

/**
* Encode an image to thumbhash string - base64 encoded.
*
Expand All @@ -65,9 +73,7 @@ public function setDriver(string $driver): self {
public function encode(mixed $data): string
{
$imageManager = new ImageManager([
'driver' => extension_loaded($this->driver)
? $this->driver
: ($this->driver === 'imagick' ? 'gd' : 'imagick'),
'driver' => $this->driver,
]);

$data = $imageManager->make($data);
Expand Down
5 changes: 5 additions & 0 deletions tests/LaravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public function testPackageLoaded(): void
{
$hash = 'fCgGDwTnqHiHd4l/hJaHmHmHhoEHGHgA';

$this->assertSame(
'imagick',
Thumbhash::getDriver()
);

$this->assertSame(
$hash,
Thumbhash::encode(__DIR__ . '/images/5.png'),
Expand Down
15 changes: 15 additions & 0 deletions tests/ThumbhashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public function testEncode(): void
{
$hash = new Thumbhash();

$this->assertSame(
'imagick',
$hash->getDriver()
);

$this->assertSame(
'm5uDBQAS1wt3iIemifd3h4CIKUd5iZBoSQ',
$hash->encode(__DIR__ . '/images/1.png')
Expand All @@ -40,6 +45,11 @@ public function testEncodeDifferentImageWidth(): void
{
$hash = new Thumbhash();

$this->assertSame(
'imagick',
$hash->getDriver()
);

$this->assertSame(
'2quDAYAm9bZweIeXcGf+p6eXcHiTaaY',
$hash->encode(__DIR__ . '/images/4.png')
Expand Down Expand Up @@ -71,6 +81,11 @@ public function testEncodeWithGifFormat(): void
{
$hash = new Thumbhash();

$this->assertSame(
'imagick',
$hash->getDriver()
);

$this->assertSame(
'KccFVYjQSZcVZ3lwdVnGi3VwSQiG',
$hash->encode(__DIR__ . '/images/6.gif')
Expand Down

0 comments on commit b6c37be

Please sign in to comment.