F
Filament14mo 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?
4 Replies
Wiebe
WiebeOP14mo 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 Lessing13mo 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.
CGM
CGM3mo ago
I'm running into this issue as well, @Wiebe @John Lessing. Were you guys able to force an aspect ratio? I did a bunch of doc diving and found
->image()
->imageEditor()
->imageCropAspectRatio('4:5')
->image()
->imageEditor()
->imageCropAspectRatio('4:5')
This worked for me, it forces an inital crop that can be changed, but is set once saved. The user isn't necessarily required to enter the editor to set the Aspect Ratio, but they are required to enter the editor if they want to edit what is cropped. Maybe not as cool as the circle cropper, but works for a forced crop.
Want results from more Discord servers?
Add your server