Beispiel #1
0
 /**
  * Get thumbnail for given image and rendition
  *
  * @param Newscoop\Image\Rendition $rendition
  * @param Newscoop\Image\ImageInterface $image
  * @return Newscoop\Image\Thumbnail
  */
 public function getThumbnail(Rendition $rendition, ImageInterface $image)
 {
     return $rendition->getThumbnail($image, $this);
 }
Beispiel #2
0
 public function testGetThumbnailFit()
 {
     $rendition = new Rendition(1000, 1000, 'fit');
     $thumbnail = $rendition->getThumbnail(new LocalImage(self::PICTURE_LANDSCAPE), $this->imageService);
     $this->assertEquals(500, $thumbnail->width);
     $this->assertEquals(333, $thumbnail->height);
 }
 /**
  * Get article image rendition
  *
  * @param int    $articleNumber
  * @param string $renditionName
  * @param int    $width
  * @param int    $height
  * @return array
  */
 public function getArticleRenditionImage($articleNumber, $renditionName, $width = null, $height = null)
 {
     $renditions = $this->getRenditions();
     if (!array_key_exists($renditionName, $renditions)) {
         return false;
     }
     $articleRenditions = $this->getArticleRenditions($articleNumber);
     $rendition = $articleRenditions[$renditions[$renditionName]];
     if ($rendition === null) {
         return false;
     }
     try {
         if ($width !== null && $height !== null) {
             $preview = $rendition->getRendition()->getPreview($width, $height);
             $thumbnail = $preview->getThumbnail($rendition->getImage(), $this->imageService);
         } else {
             $thumbnail = $rendition->getRendition()->getThumbnail($rendition->getImage(), $this->imageService);
         }
     } catch (\Exception $e) {
         return null;
     }
     $originalRendition = new Rendition($rendition->getImage()->getWidth(), $rendition->getImage()->getHeight());
     return array('id' => $rendition->getImage()->getId(), 'src' => $thumbnail->src, 'width' => $thumbnail->width, 'height' => $thumbnail->height, 'caption' => $rendition->getImage()->getCaption(), 'photographer' => $rendition->getImage()->getPhotographer(), 'photographer_url' => $rendition->getImage()->getPhotographerUrl(), 'original' => (object) array('width' => $rendition->getImage()->getWidth(), 'height' => $rendition->getImage()->getHeight(), 'src' => $originalRendition->getThumbnail($rendition->getImage(), $this->imageService)->src));
 }