Spatie Media Library Conversion Quality NOT Applied

When I convert a PNG using the model method ->addMediaConversion() the ->quality() setting is ignored when combined with ->background('#ffffff') This is problem for all PNGs with transparent backgrounds. You have to explicitly set the background or else it ends up black in the coverted jpegs. I ran into this problem about 6 months ago...I ignored it. I just upgraded related composer packages and tried again. Still getting these results. Can anybody offer and help? (Note: "works for me" comments are not necessary and counter-productive) Thanks!
4 Replies
awcodes
awcodes6mo ago
Sounds like a bug in spatie’s package to me.
bionary
bionaryOP6mo ago
I upgraded my imagemagick in brew just now...still same error For now I created a janky work around. I added a Spatie ConversionHasBeenCompletedEvent listener. From there I re-create each conversion with proper jpeg compression The simplified version looks like this:
public function handle(ConversionHasBeenCompletedEvent $event): void
{
$media = $event->media;

if($media->mime_type == 'image/png'){

$conversionName = $event->conversion->getName();

//Replace with compressed version
$image = Image::load($media->getPath($event->conversion->getName()))
->quality(65)
->optimize()
->save();
}
}
public function handle(ConversionHasBeenCompletedEvent $event): void
{
$media = $event->media;

if($media->mime_type == 'image/png'){

$conversionName = $event->conversion->getName();

//Replace with compressed version
$image = Image::load($media->getPath($event->conversion->getName()))
->quality(65)
->optimize()
->save();
}
}
fyi: there was talk about a related bug here: https://github.com/spatie/laravel-medialibrary/issues/3502 @awcodes Adam, I was going to file a bug at https://github.com/filamentphp/spatie-laravel-media-library-plugin but it is READ ONLY.
awcodes
awcodes6mo ago
yea, i just don't think Filament is doing anything specific to that functionality, which makes me think it's something in the underlying package.
bionary
bionaryOP6mo ago
Roger that. I'll post a bug at Spaties Github
Want results from more Discord servers?
Add your server