/** * Get thumbnail for given image * * @param string $image * @param int $width * @param int $height * @param string $specs * @return mixin */ public function thumbnail($image, $width, $height, $specs) { if (is_string($image)) { $image = new LocalImage($image); } return $this->imageService->getThumbnail(new Rendition($width, $height, $specs), $image); }
public function testGetThumbnail() { $rendition = new Rendition(200, 200, 'crop'); $image = new LocalImage(self::PICTURE_LANDSCAPE); $thumbnail = $this->service->getThumbnail($rendition, $image); $this->assertEquals($this->service->getSrc(self::PICTURE_LANDSCAPE, 200, 200, 'crop'), $thumbnail->src); $this->assertEquals(200, $thumbnail->width); $this->assertEquals(200, $thumbnail->height); }
/** * Get rendition preview * * @param Newscoop\Image\Rendition $rendition * @param int $width * @param int $height * @param Newscoop\Image\ArticleRendition $articleImageRendition * @return string */ public function rendition(Rendition $rendition, $width, $height, ArticleRendition $articleRendition = null) { if ($articleRendition !== null) { $preview = $articleRendition->getRendition()->getPreview($width, $height); $preview->setCoords($articleRendition->getImageSpecs()); $thumbnail = $rendition->fits($articleRendition->getImage()) ? $this->imageService->getThumbnail($preview, $articleRendition->getImage()) : null; } else { $preview = $rendition->getPreview($width, $height); $thumbnail = null; } $this->view->isDefault = $thumbnail === null || $articleRendition->isDefault(); $this->view->preview = $preview; $this->view->rendition = $rendition; $this->view->thumbnail = $thumbnail; return $this->view->render('image/rendition.phtml'); }