Add heic support

This commit is contained in:
philipp lang 2024-04-30 14:13:21 +02:00
parent 820a725517
commit 09919a1c29
5 changed files with 1483 additions and 696 deletions

View File

@ -16,6 +16,7 @@
}
],
"require": {
"ext-imagick": ">=3.6.0",
"spatie/laravel-medialibrary": "^10.7",
"laravel/framework": "^9.50",
"spatie/laravel-data": "^3.1",

2153
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
namespace Zoomyboy\MedialibraryHelper;
use Imagick;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@ -160,6 +161,14 @@ class MediaController
$tmpFile = tempnam(sys_get_temp_dir(), 'media-library');
file_put_contents($tmpFile, $binaryData);
$i = (new Imagick());
$i->readImage($tmpFile);
if ($i->getImageFormat() === 'HEIC') {
$i->setFormat('jpg');
$i->writeImage($tmpFile);
}
if (null !== $maxWidth && 'image/jpeg' === mime_content_type($tmpFile)) {
Image::load($tmpFile)->width($maxWidth)->save();
}

View File

@ -35,6 +35,22 @@ test('it uploads a single file to a single file collection', function () {
$response->assertJsonMissingPath('model_id');
});
test('it uploads heig image', function () {
$this->auth()->registerModel();
$post = $this->newPost();
$content = base64_encode($this->getFile('heic.jpg', 'heic.jpg')->getContent());
$this->postJson('/mediaupload', [
'model' => 'post',
'id' => $post->id,
'collection' => 'conversionsWithDefault',
'payload' => [
'content' => $content,
'name' => 'beispiel bild.jpg',
],
])->assertStatus(201);
});
test('it uploads a single image to a single file collection', function () {
$this->auth()->registerModel();
$post = $this->newPost();

BIN
tests/stubs/heic.jpg Normal file

Binary file not shown.