-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added avif support * bump version * bump --------- Co-authored-by: Freek Van der Herten <[email protected]>
- Loading branch information
1 parent
f8e47a7
commit 83e902e
Showing
11 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Spatie\MediaLibrary\Conversions\ImageGenerators; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\MediaLibrary\Conversions\Conversion; | ||
|
||
class Avif extends ImageGenerator | ||
{ | ||
public function convert(string $file, Conversion $conversion = null): string | ||
{ | ||
$pathToImageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.png'; | ||
|
||
$image = imagecreatefromavif($file); | ||
|
||
imagepng($image, $pathToImageFile, 9); | ||
|
||
imagedestroy($image); | ||
|
||
return $pathToImageFile; | ||
} | ||
|
||
public function requirementsAreInstalled(): bool | ||
{ | ||
if (! function_exists('imagecreatefromavif')) { | ||
return false; | ||
} | ||
|
||
if (! function_exists('imagepng')) { | ||
return false; | ||
} | ||
|
||
if (! function_exists('imagedestroy')) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function supportedExtensions(): Collection | ||
{ | ||
return collect(['avif']); | ||
} | ||
|
||
public function supportedMimeTypes(): Collection | ||
{ | ||
return collect(['image/avif']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use Spatie\MediaLibrary\Conversions\ImageGenerators\Avif; | ||
|
||
it('can convert a avif', function () { | ||
$imageGenerator = new Avif(); | ||
|
||
if (! $imageGenerator->requirementsAreInstalled()) { | ||
$this->markTestSkipped('Skipping avif test because requirements to run it are not met'); | ||
} | ||
|
||
$media = $this->testModelWithoutMediaConversions->addMedia($this->getTestAvif())->toMediaCollection(); | ||
|
||
expect($imageGenerator->canConvert($media))->toBeTrue(); | ||
|
||
$imageFile = $imageGenerator->convert($media->getPath()); | ||
|
||
expect(mime_content_type($imageFile))->toEqual('image/png'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.