Laravel/PHP Articles

Articles from Laravel/PHP sites on the web

Laravel/PHP Articles
Really popular Laravel Media Library package has one less-known feature – image resizing. The best part is that it’s really simple to add, let me show you how. If you prefer video version, here it is below:And now – text version of the tutorial. This method will generate a resized thumbnail with maximum 150px width and maximum 100px height (resized proportionally) and put it in storage/app/public/[media_id]/conversions folder:In database media table, it will be saved with custom_properties of registered media name(s). And then you will be able to access that specific conversion by the same name you used here:So, if your Media Collection name is named cover, you can view the thumbnail image like this:You can also register multiple conversions for the same model, just add more rules to the method:public function registerMediaConversions(Media $media = null) { $this->addMediaConversion('thumb') ->width(150) ->height(100); $this->addMediaConversion('bigthumb') ->width(300) ->height(100); }

Sign Up For Our Newsletter

Each Week, We curate the top Laravel/PHP articles, jobs, events and More!

We'll send you a weekly email with the latest Laravel/PHP articles, jobs and events. Please review our Code of Conduct in the meantime. Talk to you soon!