Пример #1
0
 /**
  * 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);
 }
Пример #2
0
 /**
  * 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');
 }
Пример #3
0
 public function testArticleRenditions()
 {
     $this->imageService->addArticleImage(self::ARTICLE_NUMBER, new LocalImage(self::PICTURE_LANDSCAPE));
     $this->orm->persist($imageTest = new LocalImage(self::PICTURE_PORTRAIT));
     $this->orm->flush();
     $this->orm->persist($renditionThumbnail = new Rendition(200, 200, 'fit', 'thumbnail'));
     $this->orm->persist($renditionLandscape = new Rendition(200, 200, 'fill', 'landscape'));
     $this->orm->flush();
     $this->assertInstanceOf('Newscoop\\Image\\ArticleRendition', $this->service->setArticleRendition(self::ARTICLE_NUMBER, $renditionLandscape, $imageTest));
     $renditions = $this->service->getArticleRenditions(self::ARTICLE_NUMBER);
     $this->assertInstanceOf('Newscoop\\Image\\ArticleRendition', $renditions[$renditionThumbnail]);
     $this->assertContains(self::PICTURE_LANDSCAPE, $renditions[$renditionThumbnail]->getImage()->getPath());
     $this->assertTrue($renditions[$renditionThumbnail]->isDefault());
     $this->assertInstanceOf('Newscoop\\Image\\ArticleRendition', $renditions[$renditionLandscape]);
     $this->assertContains(self::PICTURE_PORTRAIT, $renditions[$renditionLandscape]->getImage()->getPath());
     $this->assertFalse($renditions[$renditionLandscape]->isDefault());
 }
Пример #4
0
 public function testGetThumbnail()
 {
     $this->imageService->expects($this->once())->method('getSrc')->with($this->equalTo(self::PICTURE_LANDSCAPE), $this->equalTo(300), $this->equalTo(300), $this->equalTo('crop'))->will($this->returnValue('300x300/crop/' . rawurlencode(rawurlencode(self::PICTURE_LANDSCAPE))));
     $rendition = new Rendition(300, 300, 'crop');
     $thumbnail = $rendition->getThumbnail(new LocalImage(self::PICTURE_LANDSCAPE), $this->imageService);
     $this->assertInstanceOf('Newscoop\\Image\\Thumbnail', $thumbnail);
     $this->assertContains('300x300', $thumbnail->src);
     $this->assertEquals(300, $thumbnail->width, 'thumbnail_width');
     $this->assertEquals(300, $thumbnail->height, 'thumbnail_height');
 }
Пример #5
0
 public function testFindBy()
 {
     $this->assertEquals(0, count($this->service->findBy(array())));
     $this->assertEquals(0, $this->service->getCountBy(array()));
     $this->orm->persist(new LocalImage(self::PICTURE_LANDSCAPE));
     $this->orm->persist(new LocalImage('file://' . realpath(APPLICATION_PATH . '/../' . self::PICTURE_LANDSCAPE)));
     $this->orm->flush();
     $this->assertEquals(2, count($this->service->findBy(array())));
     $this->assertEquals(2, $this->service->getCountBy(array()));
 }
Пример #6
0
 /**
  * Get article renditions
  *
  * @param int $articleNumber
  * @return array
  */
 public function getArticleRenditions($articleNumber)
 {
     try {
         $articleRenditions = $this->orm->getRepository('Newscoop\\Image\\ArticleRendition')->findBy(array('articleNumber' => (int) $articleNumber));
     } catch (\Exception $e) {
         $this->createSchemaIfMissing($e);
         $articleRenditions = array();
     }
     $defaultArticleImage = $this->imageService->getDefaultArticleImage($articleNumber);
     return new ArticleRenditionCollection($articleNumber, $articleRenditions, $defaultArticleImage ? $defaultArticleImage->getImage() : null);
 }