ebess / advanced-nova-media-library

A Laravel Nova field for displaying, creating, updating and ordering a Spatie Media Library model.
591 stars 295 forks source link

How to reduce the resolution of original photos when uploading? #394

Open rik43 opened 1 year ago

rik43 commented 1 year ago

1) Users upload original photos from the phone at 10+Mpx. How to reduce photo resolution when uploading e.g. to 1600px on the long side?

2) Need to reduce the resolution of previously uploaded original photos.

Any ideas?

beshoo commented 1 year ago

+1

rik43 commented 1 year ago

temporarily made a script that goes through all the media, and if their file size and resolution are greater than the specified one, it reduces them, overwriting the original file. The file size is checked first - it's fast. This is not suitable for those who have a lot of media, but for an online store it suits.

beshoo commented 1 year ago

can you share the code?

rik43 commented 1 year ago

here. https://gist.github.com/rik43/3752894678b6c067d247e3e3d0e595e3 but keep in mind that we have our own custom path generator. file paths are not standard.