Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom save media #9

Open
projct1 opened this issue Jan 14, 2024 · 2 comments
Open

Custom save media #9

projct1 opened this issue Jan 14, 2024 · 2 comments

Comments

@projct1
Copy link

projct1 commented Jan 14, 2024

Can you add option for customize adding media?
Or just make public/protected method addMedia
I want to prepare image before save:

class MediaLibrary extends \VI\MoonShineSpatieMediaLibrary\Fields\MediaLibrary
{
    public function addMedia(HasMedia $item, UploadedFile $file): Media
    {
        $filename = $file->getPath() . '/' . $item->slug . '.webp';

        SpatieImage::load($file->getRealPath())
            ->fit(Fit::Fill, 1920, 1080)
            ->optimize()
            ->save($filename);

        $item->addMedia($filename)->withResponsiveImages()->toMediaCollection();
    }
}

It is possible?

@alexvenga
Copy link
Member

You can use MediaConversions

@projct1
Copy link
Author

projct1 commented Jan 16, 2024

You can use MediaConversions

No, i dont want store fat original file.
Spatie says about it here spatie/laravel-medialibrary#3447 (comment)
I want add already optimized file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants