Ejemplo n.º 1
0
 /**
  * Creates thumbnail.
  *
  * Internal routine for creating thumbnail.
  *
  * @param SystemPlugin_Imagine_Image  $image    Base image for thumbnail
  * @param SystemPlugin_Imagine_Preset $preset   Preset with options
  *
  * @throws Exception Rethrows Imagine exception on thumbnail creation failure.
  *
  * @return SystemPlugin_Imagine_Image
  */
 private function createThumbnail(SystemPlugin_Imagine_Image $image, SystemPlugin_Imagine_Preset $preset)
 {
     $options = array();
     if (isset($preset['options']) || !is_array($preset['options'])) {
         $options = $preset['options'];
     }
     if (isset($preset['mode']) && $preset['mode'] === 'inset') {
         $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
     } else {
         $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
     }
     // check for w/h autoscaling and scale to ratio
     if ($preset['height'] == 'auto') {
         $imageSize = @getimagesize($image->getRealPath());
         $preset['height'] = round($imageSize[1] / $imageSize[0] * $preset['width']);
     }
     if ($preset['width'] == 'auto') {
         $imageSize = @getimagesize($image->getRealPath());
         $preset['width'] = round($imageSize[0] / $imageSize[1] * $preset['height']);
     }
     $size = new \Imagine\Image\Box($preset['width'], $preset['height']);
     try {
         $this->getTransformation()->apply($this->getImagine()->open($image->getRealPath()))->thumbnail($size, $mode)->save($image->getThumbRealPath(), $options);
     } catch (Exception $exception) {
         throw $exception;
     }
     return $image;
 }
Ejemplo n.º 2
0
    /**
     * Creates thumbnail.
     *
     * Internal routine for creating thumbnail.
     *
     * @param SystemPlugin_Imagine_Image  $image    Base image for thumbnail
     * @param SystemPlugin_Imagine_Preset $preset   Preset with options
     *
     * @throws Exception Rethrows Imagine exception on thumbnail creation failure.
     *
     * @return SystemPlugin_Imagine_Image
     */
    private function createThumbnail(SystemPlugin_Imagine_Image $image, SystemPlugin_Imagine_Preset $preset)
    {

        if (isset($preset['mode']) && $preset['mode'] === 'inset') {
            $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
        } else {
            $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
        }
        $size = new \Imagine\Image\Box($preset['width'], $preset['height']);

        try {
            $this->getTransformation()
                ->apply($this->getImagine()->open($image->getRealPath()))
                ->thumbnail($size, $mode)
                ->save($image->getThumbRealPath());
        } catch (Exception $exception) {
            throw $exception;
        }

        return $image;
    }