eine91's avatar

Spatie Media-Library - resize main image while adding it to media

Hi, I am using Spatie media library.

I wanted to know is it possible to resize main image itself while it to media.

I have added below method to my model for 2nd resized image:

public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('tour-images-medium') ->width(360) ->height(240); }

Above is working great as expected. So in the end I have 2 images, 1st is main image which is uploaded & 2nd is converted image through above method.

But I wanted to resize main image in 500x500 dimesion, so that if user uploaded 1024x800 image, in the end I should have 1. 500x500 & 2. 360x240 px images and not 1024x800.

I could write anothe addMediaConversion() method for 500x500. But it will result in total 3 images which I don't want.

0 likes
2 replies
bobbybouwmann's avatar

The media library package doesn't support this functionality.

The reason being is that the original image is needed to perform certain actions in the package. You can of course delete the original image yourself after you're done with upload but I wouldn't recommend that ;)

Please or to participate in this conversation.