Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
philipp lang | 4a87b83b5a | |
philipp lang | 09919a1c29 |
|
@ -16,6 +16,7 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"ext-imagick": ">=3.6.0",
|
||||
"spatie/laravel-medialibrary": "^10.7",
|
||||
"laravel/framework": "^9.50",
|
||||
"spatie/laravel-data": "^3.1",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,7 +8,8 @@ class CollectionExtension
|
|||
{
|
||||
public function boot(): void
|
||||
{
|
||||
MediaCollection::mixin(new class() {
|
||||
MediaCollection::mixin(new class()
|
||||
{
|
||||
public function forceFileName()
|
||||
{
|
||||
return fn ($callback) => $this->registerCustomCallback('forceFileName', $callback);
|
||||
|
@ -86,7 +87,7 @@ class CollectionExtension
|
|||
'after' => fn ($event) => true,
|
||||
'destroyed' => fn ($event) => true,
|
||||
'storing' => fn ($adder, $name) => $adder,
|
||||
'withDefaultProperties' => fn ($path) => [],
|
||||
'withDefaultProperties' => fn ($path, $pathinfo) => [],
|
||||
'withPropertyValidation' => fn ($path) => [],
|
||||
'withFallback' => fn ($parent) => null,
|
||||
]);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Zoomyboy\MedialibraryHelper;
|
||||
|
||||
use Imagick;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
@ -53,7 +54,7 @@ class MediaController
|
|||
$adder = $this->fileAdderFromData($model, $c['content'], $collection)
|
||||
->usingName($basename)
|
||||
->usingFileName($path)
|
||||
->withCustomProperties($collection->runCallback('withDefaultProperties', $path));
|
||||
->withCustomProperties($collection->runCallback('withDefaultProperties', $path, $pathinfo));
|
||||
|
||||
return tap(
|
||||
$collection->runCallback('storing', $adder, $path)->toMediaCollection($collection->name),
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -56,7 +56,7 @@ class Post extends Model implements HasMedia
|
|||
Event::dispatch(new MediaStored($media));
|
||||
});
|
||||
|
||||
$this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path) => [
|
||||
$this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path, $pathinfo) => [
|
||||
'test' => Str::camel($path),
|
||||
])->withPropertyValidation(fn ($path) => [
|
||||
'test' => 'string|max:10',
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue