F
Filament9mo ago
Wiebe

Require cropping to a certain size before submitting

Is there a way to require the user to crop the image to a certain ratio?
3 Replies
Wiebe
Wiebe9mo ago
@Barney thanks, but that way its optional. In my case the user MUST choose a crop ratio, 21:9 or 16:9 to continue. I used fillament croppy before, but that one doesnt work with filament v3
John Lessing
John Lessing8mo ago
Hello there, I'm struggling with a similar use case, so I hope, posting to this thread is the right call: I'd like to force the user to crop the image for e.g. a profile picture to a 1:1 aspect ratio. So far I tried two options:
FileUpload::make('image')
->image()
->imageEditor()
->imageEditorAspectRatios(['1:1']),
FileUpload::make('image')
->image()
->imageEditor()
->imageEditorAspectRatios(['1:1']),
Hereby the user must actively click on the edit button to access the editor and the 1:1 aspect ratio isn't enforced. It just adds buttons for setting the crop tool to specific aspect ratios. In my case with only one ratio given, there isn't even a button present. I tried this code instead:
FileUpload::make('image')
->image()
->imageResizeMode('cover')
->imageCropAspectRatio('1:1'),
FileUpload::make('image')
->image()
->imageResizeMode('cover')
->imageCropAspectRatio('1:1'),
This automatically crops the image to a square in the middle of the source file with no chance for the user to specify the correct location in case the face is offset in the source file. I'm sorry, if I'm missing something completely obvious, but I'm new to PHP 8 and Laravel. I hope, one of you can nudge me in the right direction.
Want results from more Discord servers?
Add your server
More Posts