예제 #1
0
 public function resize(\Symforce\AdminBundle\Entity\File $file, $_crop, array $config)
 {
     $crop = json_decode($_crop, true);
     $imagine = $this->getImagine();
     $box_size = new \Imagine\Image\Box($config[0][0] / $crop['width'], $config[0][1] / $crop['height']);
     $crop_point = new \Imagine\Image\Point($box_size->getWidth() * $crop['left'], $box_size->getHeight() * $crop['top']);
     $crop_size = new \Imagine\Image\Box($config[0][0], $config[0][1]);
     while ($crop_point->getX() + $crop_size->getWidth() > $box_size->getWidth()) {
         if ($crop_point->getX() < 1) {
             break;
         }
         $crop_point = new \Imagine\Image\Point($crop_point->getX() - 1, $crop_point->getY());
     }
     while ($crop_point->getY() + $crop_size->getHeight() > $box_size->getHeight()) {
         if ($crop_point->getY() < 1) {
             break;
         }
         $crop_point = new \Imagine\Image\Point($crop_point->getX(), $crop_point->getY() - 1);
     }
     $options = array('quality' => 100);
     $img = $imagine->load(stream_get_contents($file->getContent()));
     $img->resize($box_size)->crop($crop_point, $crop_size);
     $data = $img->get($file->getExt(), $options);
     $stream = fopen('php://memory', 'r+');
     fwrite($stream, $data);
     rewind($stream);
     $file->setContent($stream);
     if ($config[1][0] && $config[1][1]) {
         $small_box = new \Imagine\Image\Box($config[1][0], $config[1][1]);
         $img = $imagine->load($data)->resize($small_box);
         $small_data = $img->get($file->getExt(), $options);
         $small_stream = fopen('php://memory', 'r+');
         fwrite($small_stream, $small_data);
         rewind($small_stream);
         $file->setPreview($small_stream);
     }
     $file->setUpdated(new \DateTime('now'));
 }
예제 #2
0
 /**
  * Metodo para procesar y cargar las imagenes ya revisadas
  */
 private function loadYprocesaImg($fnew, $oldName, $newName, $file)
 {
     $return = array('abort' => FALSE, 'msg' => '');
     $ext = $fnew->getClientOriginalExtension();
     //Primero procesamos el archivo de los datos
     $rota = count($file['fotos']['sec']);
     $nomFoto = null;
     for ($f = 0; $f < $rota; $f++) {
         if ($file['fotos']['sec'][$f] == trim($oldName)) {
             $nomFoto = 'fajas-colombianas-gdl_' . $newName . '_' . $f . '.' . $ext;
             $file['fotos']['sec'][$f] = $nomFoto;
             break;
         }
     }
     $pat = realpath($this->getParameter('kernel.root_dir') . '/../web/data/' . $newName . '.json');
     $patI = realpath($this->getParameter('kernel.root_dir') . '/../web/fotos/');
     try {
         file_put_contents($pat, json_encode($file), LOCK_EX);
     } catch (Exception $ex) {
         $return['abort'] = TRUE;
         $return['msg'] = 'No se pudo guardar el Archivo Principal.';
         return $return;
     }
     $imgi = new \Imagine\Gd\Imagine();
     $fi = $imgi->open($fnew->getRealPath());
     $fileWidth = $fi->getSize()->getWidth();
     if ($fileWidth < 600) {
         $return['abort'] = TRUE;
         $return['msg'] = 'La foto es muy pequeña, necesitas una mas grande.';
         return $return;
     }
     try {
         $tamOri = new \Imagine\Image\Box($fi->getSize()->getWidth(), $fi->getSize()->getHeight());
         $tamLg = $tamOri->widen(600);
         $fi->resize($tamLg)->save($patI . '/lg/' . $nomFoto);
         $tamSm = $tamOri->widen(280);
         $fi->resize($tamSm)->save($patI . '/sm/' . $nomFoto);
         $tamXs = $tamOri->widen(120);
         $fi->resize($tamXs)->save($patI . '/xs/' . $nomFoto);
     } catch (Exception $ex) {
         $return['abort'] = TRUE;
         $return['msg'] = 'Error al guardar Imagen.';
         return $return;
     }
     $return['abort'] = FALSE;
     $return['msg'] = 'ok.';
     return $return;
 }