src/Controller/DefaultController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Gregwar\Image\Image;
  4. use Gregwar\ImageBundle\DependencyInjection\Configuration;
  5. use Gregwar\ImageBundle\GregwarImageBundle;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  11. class DefaultController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/fotos/{indice}/{object_id}/{foto}", methods={"GET"}, name="fotos")
  15.      */
  16.     public function fotos($indice,$object_id,$foto)
  17.     {
  18.         $width = (int) $_GET['w']? $_GET['w']: 500;
  19.         $height = (int) $_GET['h']? $_GET['h']: 333;
  20.         $crop $_GET['crop'];
  21.         $foto_url __DIR__.'/../../public/uploads/'.$indice.'/'.$object_id.'/'.$foto;
  22.         if(!file_exists(__DIR__.'/../../public/uploads/'.$indice.'/'.$object_id.'/'.$foto)){
  23.             $foto_url __DIR__.'/../../public/imgs/transparent.png';
  24.         }
  25.         if($crop){
  26.             $foto_cache __DIR__.'/../../public/'.Image::open($foto_url)->zoomCrop($width,$height,'transparent');
  27.         }
  28.         else{
  29.             $foto_cache __DIR__.'/../../public/'.Image::open($foto_url)->resize($width,$height);
  30.         }
  31.         return new BinaryFileResponse($foto_cache);
  32.     }
  33. }