Commit 7f01a538789a7e3d041588854988b043dc01432a
1 parent
915ebbf7f0
Exists in
master
creada la funcion thumbnail que permite guardar las minuaturas de los documentos cargads
Showing
1 changed file
with
38 additions
and
3 deletions
Show diff stats
src/AppBundle/Controller/AdscripcionController.php
| ... | ... | @@ -51,18 +51,21 @@ class AdscripcionController extends Controller |
| 51 | 51 | |
| 52 | 52 | // Generate a unique name for the file before saving it |
| 53 | 53 | $nombreTrabajo = md5(uniqid()).'.'.$constanciaTrabajo->guessExtension(); |
| 54 | - $nombrePregrado = md5(uniqid()).'.'.$constanciaPregrado->guessExtension(); | |
| 54 | + | |
| 55 | 55 | |
| 56 | 56 | // Move the file to the directory where brochures are stored |
| 57 | 57 | $constanciaTrabajo->move( |
| 58 | 58 | $this->container->getParameter('adscripcion_directory'), |
| 59 | 59 | $nombreTrabajo |
| 60 | - ); | |
| 61 | - | |
| 60 | + ); | |
| 61 | + thumbnail($nombreTrabajo, $this->container->getParameter('adscripcion_directory'), $this->container->getParameter('adscripcion_thumb_directory')); | |
| 62 | + | |
| 63 | + $nombrePregrado = md5(uniqid()).'.'.$constanciaPregrado->guessExtension(); | |
| 62 | 64 | $constanciaPregrado->move( |
| 63 | 65 | $this->container->getParameter('adscripcion_directory'), |
| 64 | 66 | $nombrePregrado |
| 65 | 67 | ); |
| 68 | + thumbnail($nombrePregrado, $this->container->getParameter('adscripcion_directory'), $this->container->getParameter('adscripcion_thumb_directory')); | |
| 66 | 69 | |
| 67 | 70 | if($form->get('postgrado')->getData()) { |
| 68 | 71 | /** @var UploadedFile $constanciaPostgrado */ |
| ... | ... | @@ -72,6 +75,7 @@ class AdscripcionController extends Controller |
| 72 | 75 | $this->container->getParameter('adscripcion_directory'), |
| 73 | 76 | $nombrePostgrado |
| 74 | 77 | ); |
| 78 | + thumbnail($nombrePostgrado, $this->container->getParameter('adscripcion_directory'), $this->container->getParameter('adscripcion_thumb_directory')); | |
| 75 | 79 | $adscripcion->setPostgrado($nombrePostgrado); |
| 76 | 80 | } |
| 77 | 81 | $em = $this->getDoctrine()->getManager(); |
| ... | ... | @@ -97,6 +101,7 @@ class AdscripcionController extends Controller |
| 97 | 101 | $this->container->getParameter('adscripcion_directory'), |
| 98 | 102 | $nombreOposicion |
| 99 | 103 | ); |
| 104 | + thumbnail($nombreOposicion, $this->container->getParameter('adscripcion_directory'), $this->container->getParameter('adscripcion_thumb_directory')); | |
| 100 | 105 | $adscripcion->setOposicion($nombreOposicion); |
| 101 | 106 | $adscripcion->setIdLineaInvestigacion($form->get('lineas_investigacion')->getData()); |
| 102 | 107 | $adscripcion->setTituloTrabajo($form->get('titulo_trabajo')->getData()); |
| ... | ... | @@ -120,6 +125,7 @@ class AdscripcionController extends Controller |
| 120 | 125 | $this->container->getParameter('adscripcion_directory'), |
| 121 | 126 | $nombreAsistente |
| 122 | 127 | ); |
| 128 | + thumbnail($nombreAsistente, $this->container->getParameter('adscripcion_directory'), $this->container->getParameter('adscripcion_thumb_directory')); | |
| 123 | 129 | $adscripcion->setAsistente($nombreAsistente); |
| 124 | 130 | |
| 125 | 131 | |
| ... | ... | @@ -140,6 +146,7 @@ class AdscripcionController extends Controller |
| 140 | 146 | $this->container->getParameter('adscripcion_directory'), |
| 141 | 147 | $nombreAsociado |
| 142 | 148 | ); |
| 149 | + thumbnail($nombreAsociado, $this->container->getParameter('adscripcion_directory'), $this->container->getParameter('adscripcion_thumb_directory')); | |
| 143 | 150 | $adscripcion->setAsociado($nombreAsociado); |
| 144 | 151 | } |
| 145 | 152 | |
| ... | ... | @@ -159,6 +166,7 @@ class AdscripcionController extends Controller |
| 159 | 166 | $this->container->getParameter('adscripcion_directory'), |
| 160 | 167 | $nombreAgregado |
| 161 | 168 | ); |
| 169 | + thumbnail($nombreAgregado, $this->container->getParameter('adscripcion_directory'), $this->container->getParameter('adscripcion_thumb_directory')); | |
| 162 | 170 | $adscripcion->setAgreado($nombreAgregado); |
| 163 | 171 | } |
| 164 | 172 | |
| ... | ... | @@ -178,6 +186,7 @@ class AdscripcionController extends Controller |
| 178 | 186 | $this->container->getParameter('adscripcion_directory'), |
| 179 | 187 | $nombreTitular |
| 180 | 188 | ); |
| 189 | + thumbnail($nombreTitular, $this->container->getParameter('adscripcion_directory'), $this->container->getParameter('adscripcion_thumb_directory')); | |
| 181 | 190 | $adscripcion->setTitular($nombreTitular); |
| 182 | 191 | } |
| 183 | 192 | |
| ... | ... | @@ -200,3 +209,29 @@ class AdscripcionController extends Controller |
| 200 | 209 | ); |
| 201 | 210 | } |
| 202 | 211 | } |
| 212 | + | |
| 213 | +/*funcion para crear miniaturas de las imagenes y carga más rapido la página */ | |
| 214 | + | |
| 215 | +function thumbnail ($filename, $fuente, $destino){ | |
| 216 | + if(preg_match('/[.](jpeg)$/', $filename)) { | |
| 217 | + $im = imagecreatefromjpeg($fuente . "/" . $filename); | |
| 218 | + } else if (preg_match('/[.](jpg)$/', $filename)) { | |
| 219 | + $im = imagecreatefromjpeg($fuente . "/" . $filename); | |
| 220 | + }else if (preg_match('/[.](gif)$/', $filename)) { | |
| 221 | + $im = imagecreatefromgif($fuente . "/" . $filename); | |
| 222 | + } else if (preg_match('/[.](png)$/', $filename)) { | |
| 223 | + $im = imagecreatefrompng($fuente . "/" . $filename); | |
| 224 | + } | |
| 225 | + | |
| 226 | + $ox = imagesx($im); | |
| 227 | + $oy = imagesy($im); | |
| 228 | + | |
| 229 | + $nx = 80; | |
| 230 | + $ny = 80; | |
| 231 | + | |
| 232 | + $nm = imagecreatetruecolor($nx, $ny); | |
| 233 | + | |
| 234 | + imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy); | |
| 235 | + | |
| 236 | + imagejpeg($nm, $destino . "/" . $filename); | |
| 237 | +} | ... | ... |