spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

recreate BackedEnums when applying Manipulations #3584

Closed tkempf closed 6 months ago

tkempf commented 7 months ago

Fixes Issue #3582

MrMeshok commented 6 months ago

There is also valid usage without named parameters

$media->manipulations = [
    'default' => [
        'border' => [
            1,
            BorderType::Expand,
            '000000'
        ]
    ]
];

I see 2 solutions there:

  1. Try to find enum from parameters array by named parameter key or numeric position e.g. BorderType::from($parameters['type'] ?? $parameters[1])
  2. Use reflection and check ImageDriver method parameters before calling it

Obviously reflection would be better, but there performance concerns, so it needs benchmarking.

I could take over this issue as this also need for my use case

timvandijck commented 6 months ago

@tkempf thank you for your work!

@MrMeshok I'm going to already merge this PR, but if you have some more improvements on this topic I would be happy to look at a new PR from you.