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

How to optimize and replace the original image when uploading to media? #1526

Closed
sushiljic opened this issue Aug 13, 2019 · 3 comments
Closed

Comments

@sushiljic
Copy link

On the $post,there will be request featured containing image of the post,
i have used conversion to create the thumb of the image but i want to optimize the image also original one.
i am using
$post->addMediaFromRequest('featured')->toMediaCollection('featured');
Where on the Post model
$this->addMediaConversion('thumb') ->width(env('THUMB_WIDTH',150)) ->height(env('THUMB_HEIGHT',150)) ->performOnCollections('featured');

I find the thumb image is being optimized but not original one.
I could not even find on the documentation too.

@freekmurze
Copy link
Member

The medialibrary doesn’t make any changes to the original file. If you want to optimize the a file, you’ll have to do it yourself before adding it to the medialibrary.

@madalinignisca
Copy link

madalinignisca commented Apr 7, 2021

Is there an event before adding the file to medialibrary?
I'd like to apply optimization on it, for example when using images given by URL. Would be nice to have an event allowing me to manipulate the file just before it is added to medialibrary.

NVM, I can work it on Spatie\MediaLibrary\MediaCollections\Events\MediaHasBeenAdded

@Tofandel
Copy link
Contributor

Tofandel commented Aug 18, 2022

That's a bit sad given that the lib can already do conversions, we would have to reinvent the wheel to do our own optimizations, it would be such a good addition if we could do

$this->addMediaConversion('original') ->width(500)->height(500)
->performOnCollections('featured')
->performOnOriginalImage(); // Or replaceOriginal()

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

Successfully merging a pull request may close this issue.

4 participants