<?php
namespace App\Controller;
use Gregwar\Image\Image;
use Gregwar\ImageBundle\DependencyInjection\Configuration;
use Gregwar\ImageBundle\GregwarImageBundle;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class DefaultController extends AbstractController
{
/**
* @Route("/fotos/{indice}/{object_id}/{foto}", methods={"GET"}, name="fotos")
*/
public function fotos($indice,$object_id,$foto)
{
$width = (int) $_GET['w']? $_GET['w']: 500;
$height = (int) $_GET['h']? $_GET['h']: 333;
$crop = $_GET['crop'];
$foto_url = __DIR__.'/../../public/uploads/'.$indice.'/'.$object_id.'/'.$foto;
if(!file_exists(__DIR__.'/../../public/uploads/'.$indice.'/'.$object_id.'/'.$foto)){
$foto_url = __DIR__.'/../../public/imgs/transparent.png';
}
if($crop){
$foto_cache = __DIR__.'/../../public/'.Image::open($foto_url)->zoomCrop($width,$height,'transparent');
}
else{
$foto_cache = __DIR__.'/../../public/'.Image::open($foto_url)->resize($width,$height);
}
return new BinaryFileResponse($foto_cache);
}
}