Skip to content

Commit

Permalink
Add support of jfif (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
clementbirkle authored Apr 17, 2024
1 parent 85dd6ba commit 05166a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Drivers/Gd/GdDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function save(?string $path = null): static
switch (strtolower($extension)) {
case 'jpg':
case 'jpeg':
case 'jfif':
imagejpeg($this->image, $path, $this->quality);
break;
case 'png':
Expand Down Expand Up @@ -185,6 +186,7 @@ public function base64(string $imageFormat = 'jpeg', bool $prefixWithFormat = tr
switch (strtolower($imageFormat)) {
case 'jpg':
case 'jpeg':
case 'jfif':
imagejpeg($this->image, null, $this->quality);
break;
case 'png':
Expand Down
8 changes: 7 additions & 1 deletion src/Drivers/Imagick/ImagickDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ public function save(?string $path = null): static

$extension = pathinfo($path, PATHINFO_EXTENSION);

if (! in_array(strtoupper($extension), Imagick::queryFormats('*'))) {
$formats = Imagick::queryFormats('*');

if (in_array('JPEG', $formats)) {
$formats[] = 'JFIF';
}

if (! in_array(strtoupper($extension), $formats)) {
throw UnsupportedImageFormat::make($extension);
}

Expand Down
10 changes: 8 additions & 2 deletions tests/ImageFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@

$driver->loadFile(getTestJpg())->save($targetFile);

expect($targetFile)->toHaveMime("image/$format");
})->with('drivers', ['jpeg', 'gif', 'png', 'webp', 'avif']);
$expectedFormat = $format;

if (in_array($expectedFormat, ['jpg', 'jfif'])) {
$expectedFormat = 'jpeg';
}

expect($targetFile)->toHaveMime("image/$expectedFormat");
})->with('drivers', ['jpeg', 'jpg', 'jfif', 'gif', 'png', 'webp', 'avif']);

it('can save supported formats using format() function', function (ImageDriver $driver, string $format) {
if ($format === 'avif' && ! avifIsSupported($driver->driverName())) {
Expand Down

0 comments on commit 05166a6

Please sign in to comment.