Example #1
0
 /**
  * Use Imagine to crop an image and do not return it's new path
  *
  * @param string $originalImage
  * @param array $arguments
  * @param array $imageOptions
  *
  * @return void
  *
  * @throws ErrorException
  */
 public function doFilter($originalImage, $arguments, $imageOptions)
 {
     switch (strtolower($imageOptions['imageProcessor'])) {
         case 'gd':
             $Imagine = new \Imagine\Gd\Imagine();
             break;
         case 'imagick':
             $Imagine = new \Imagine\Imagick\Imagine();
             break;
         case 'gmagick':
             $Imagine = new \Imagine\Gmagick\Imagine();
             break;
         default:
             throw new ErrorException('Unsupported imageProcessor config value: ' . $imageOptions['imageProcessor']);
     }
     $image = $Imagine->open($originalImage);
     $size = $image->getSize();
     $width = empty($arguments['width']) ? $size->getWidth() : $arguments['width'];
     $height = empty($arguments['height']) ? $size->getHeight() : $arguments['height'];
     $x = empty($arguments['x']) ? 0 : $arguments['x'];
     $y = empty($arguments['y']) ? 0 : $arguments['y'];
     if ($width > $imageOptions['maxAllowedResizeWidth']) {
         $width = $imageOptions['maxAllowedResizeWidth'];
     }
     if ($height > $imageOptions['maxAllowedResizeHeight']) {
         $height = $imageOptions['maxAllowedResizeHeight'];
     }
     $newImage = $image->crop(new Point($x, $y), new Box($width, $height));
     $newImage->save($originalImage, array('jpeg_quality' => $arguments['quality']));
 }
 protected function create_scaled_image($file_name, $options)
 {
     $imagine = new \Imagine\Gmagick\Imagine();
     $size = new \Imagine\Image\Box($options['max_width'], $options['max_height']);
     $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
     $file_path = $this->options['upload_dir'] . $file_name;
     $new_file_path = $options['upload_dir'] . $file_name;
     $success = $imagine->open($file_path)->resize($size, $mode)->save($new_file_path);
     return $success;
 }
 public function adicionar($foto = NULL)
 {
     if ($foto) {
         $foto = base64_decode($foto);
         $imagine = new \Imagine\Gmagick\Imagine();
         $size = new \Imagine\Image\Box(615, 302);
         $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
         $srcfotodir = LITHIUM_APP_PATH . '/webroot/img/original/';
         $destfotodir = LITHIUM_APP_PATH . '/webroot/img/projectos/galeria/';
         $imagine->open($srcfotodir . $foto)->resize($size, $mode)->save($destfotodir . $foto);
         $galeria = Galeria::find('first');
         $fotos = $galeria->foto->to('array');
         array_push($fotos, $foto);
         $galeria->foto = $fotos;
         $galeria->save();
     }
     $this->redirect('Galeria::index');
 }
 public function teste()
 {
     $imagine = new \Imagine\Gmagick\Imagine();
     $size = new \Imagine\Image\Box(635, 381);
     $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
     $projectos = Construcao::find('all', array('order' => array('ordem' => 'ASC'), 'fields' => 'foto', "limit" => 3, "page" => 4));
     $fotos = [];
     foreach ($projectos as $projecto) {
         foreach ($projecto->to('array') as $fotoarray) {
             foreach ($fotoarray as $foto) {
                 array_push($fotos, $foto);
             }
         }
     }
     $cont = 0;
     foreach (glob(LITHIUM_APP_PATH . "/webroot/img/projectos/*.jpg") as $srcimg) {
         $imgname = substr($srcimg, -20);
         if (in_array($imgname, $fotos)) {
             $new_file_path = Libraries::get(true, 'path') . '/webroot/img/projectos/grandes/' . $imgname;
             $success = $imagine->open($srcimg)->resize($size, $mode)->save($new_file_path);
             if ($success) {
                 echo "done {$imgname} </br>";
             }
         }
     }
     echo $cont;
 }
Example #5
0
 /**
  * Use Imagine to resize an image and return it's new path
  *
  * @param string $originalImage
  * @param array $arguments
  * @param array $imageOptions
  *
  * @return void
  *
  * @throws ErrorException
  */
 public function doFilter($originalImage, $arguments, $imageOptions)
 {
     // Need at least a height or a width
     if (empty($arguments['height']) && empty($arguments['width'])) {
         throw new ErrorException('You must set at least the height (h) or the width (w)');
     }
     switch (strtolower($imageOptions['imageProcessor'])) {
         case 'gd':
             $Imagine = new \Imagine\Gd\Imagine();
             break;
         case 'imagick':
             $Imagine = new \Imagine\Imagick\Imagine();
             break;
         case 'gmagick':
             $Imagine = new \Imagine\Gmagick\Imagine();
             break;
         default:
             throw new ErrorException('Unsupported imageProcessor config value: ' . $imageOptions['imageProcessor']);
     }
     $image = $Imagine->open($originalImage);
     $size = $image->getSize();
     $originalWidth = $size->getWidth();
     $originalHeight = $size->getHeight();
     $width = $originalWidth;
     $height = $originalHeight;
     if (!empty($arguments['height'])) {
         if ($originalHeight > $arguments['height'] || $arguments['stretch']) {
             $height = $arguments['height'];
         }
     }
     if (!empty($arguments['width'])) {
         if ($originalWidth > $arguments['width'] || $arguments['stretch']) {
             $width = $arguments['width'];
         }
     }
     /**
      * Prevent from someone from creating huge images
      */
     if ($width > $imageOptions['maxAllowedResizeWidth']) {
         $width = $imageOptions['maxAllowedResizeWidth'];
     }
     if ($height > $imageOptions['maxAllowedResizeHeight']) {
         $height = $imageOptions['maxAllowedResizeHeight'];
     }
     $mode = $arguments['exact'] ? ImageInterface::THUMBNAIL_OUTBOUND : ImageInterface::THUMBNAIL_INSET;
     $newSize = new Box($width, $height);
     $newImage = $image->thumbnail($newSize, $mode);
     if ($arguments['fill']) {
         $adjustedSize = $newImage->getSize();
         $canvasWidth = isset($arguments['width']) ? $arguments['width'] : $adjustedSize->getWidth();
         $canvasHeight = isset($arguments['height']) ? $arguments['height'] : $adjustedSize->getHeight();
         /**
          * Prevent from someone from creating huge images
          */
         if ($canvasWidth > $imageOptions['maxAllowedResizeWidth']) {
             $canvasWidth = $imageOptions['maxAllowedResizeWidth'];
         }
         if ($canvasHeight > $imageOptions['maxAllowedResizeHeight']) {
             $canvasHeight = $imageOptions['maxAllowedResizeHeight'];
         }
         $canvas = $Imagine->create(new Box($canvasWidth, $canvasHeight), new Color($arguments['fillColour']));
         // Put image in the middle of the canvas
         $newImage = $canvas->paste($newImage, new Point((int) (($canvasWidth - $adjustedSize->getWidth()) / 2), (int) (($canvasHeight - $adjustedSize->getHeight()) / 2)));
     }
     $newImage->save($originalImage, array('quality' => $arguments['quality']));
 }