Utilisation de Symfony UX Cropper
Bonjour
J'ai besoin d'aide sur l'utilisation de Symfony UX Cropper.
OBJECTIF : Je souhaite télécharger une photo via un bouton parcourir et pouvoir la recadrée.
LE PROBLEME :
Le problème c'est le traitement, je ne sais pas du tout comment je dois m'y prendre, la doc ne parle pas du tout du traitement... Je sais uploader une image classique avec Symfony mais je ne sais pas "cabler" le tout... je ne sais pas si je suis très clair dans mes explications. :roll:
Voici mon controller :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <?php
namespace App\Controller;
use Symfony\UX\Cropperjs\Form\CropperType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\UX\Cropperjs\Factory\CropperInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PhotoController extends AbstractController
{
#[Route('/photo', name: 'photo')]
public function index(CropperInterface $cropper, Request $request): Response
{
$crop = $cropper->createCrop('test.jpg');
$crop->setCroppedMaxSize(2000, 1500);
$form = $this->createFormBuilder(['crop' => $crop])
->add('crop', CropperType::class, [
'public_url' => 'test.jpg', // image que l'on souhaite cropper
'aspect_ratio' => 2000 / 1500,
'attr' => ['data-controller' => 'cropper'],
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// Get the cropped image data (as a string)
$crop->getCroppedImage();
// Create a thumbnail of the cropped image (as a string)
$crop->getCroppedThumbnail(200, 150);
// ...
}
return $this->render('photo/index.html.twig', [
'form' => $form->createView(),
]);
}
} |
Je vous remercie.