Cropper
use Symfony\UX\Cropper\Cropper;
use Symfony\UX\Cropper\Form\CropperType;
class ConferenceController extends AbstractController
{
/**
* @Route("/{_locale<%app.supported_locales%>}/comment/{id}/crop", name="comment_crop")
*/
public function crop(Request $request, Comment $comment, Cropper $cropper, string
$photoDir)
{
// Redirect to the conference page if no photo
// Otherwise, allow the user to crop the uploaded image
$crop = $cropper->createCrop($photoDir.'/'.$comment->getPhotoFilename());
$crop->setCroppedMaxSize(2000, 1500);
$form = $this->createFormBuilder(['crop' => $crop])
->add('crop', CropperType::class, [
'public_url' => '/uploads/photos/'.$comment->getPhotoFilename(),
'aspect_ratio' => 2000 / 1500,
])
->add('submit', SubmitType::class)
->getForm()
;
// Handle the form
}
}
{% block body %}
Crop your photo
{{ form(form) }}
{% endblock %}
cropper.html.twig
ConferenceController.php