spatie / laravel-medialibrary

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

Upgrade to 11: Custom optimizer ignored #3566

Closed korridor closed 6 months ago

korridor commented 8 months ago

I use a custom optimizer and register this optimizer in the config media-library.image_optimizers. Since the major 11 upgrade, the custom optimizer does not get called at all. If I add logs to the canHandle and getCommand function, nothing happens. If I downgrade, it works again, without changing anything else.


I debugged the problem a bit, and it looks to me like the problem is somewhere here:

The laravel-medialibrary only uses the image_optimizers config here to create the OptimizerChainFactory: https://github.com/spatie/laravel-medialibrary/blob/3bb61aec3505055a18323afb348ca425161019fd/src/Conversions/Conversion.php#L40

In the OptimizerChainFactory (https://github.com/spatie/image-optimizer/blob/02e2717c31334646f00a0e25cf5edbf41bd20ac3/src/OptimizerChainFactory.php#L15) the $config is being used, but it ignores custom optimizers, since the optimizers are redefined here. (https://github.com/spatie/image-optimizer/blob/02e2717c31334646f00a0e25cf5edbf41bd20ac3/src/OptimizerChainFactory.php#L35)

patinthehat commented 8 months ago

@korridor We'd be happy to accept a PR that fixes this! :+1:

timvandijck commented 6 months ago

A PR with just a failing test would be welcome too (sounds like a good first issue).

0xb4lint commented 6 months ago

I've made a PR for this issue: https://github.com/spatie/image-optimizer/pull/216

timvandijck commented 6 months ago

I just merged and published the PR, thank you!