3

I am using Laravel Nova v4.0, and am trying to resize the image before uploading it to server. Suppose someone selects an image of 8mb which is very heavy, I need to resize this image to somewhere around 100kb or 200kb and then upload to server.

I know that I can use validation, but I want the user to upload any size and the let the code resize the image. Is it possible?

I have tried this:

Image::make('Image', 'meta->image_path')
    ->required()
    ->prunable()
    ->resize(100, 100, function ($constraint) {
        $constraint->aspectRatio();
    })
    ->disk(\App\Models\SomeModel::disk())
    ->path(\App\Models\SomeModel::uploadPath())
    ->maxWidth(150)
    // ->rules("image", "max:200", "min:100")
    ->disableDownload()
    ->preview(function () {
        return $this->logo_url;
    })
    ->thumbnail(function () {
        return $this->logo_url;
    })
    ->displayUsing(function () {
        return $this->logo_url;
    }),

But i'm getting this error:

Method Laravel\Nova\Fields\Image::resize does not exist.

1
  • Laravel nova does not provide image manipulation. Any customization before storage you can do only using the method "store". Please check the documentation . For example, you can install intervention package and use it in "store" method. Commented Jan 21, 2024 at 13:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.