Example #1
0
 /**
  * Gets image url.
  *
  * @param mixed  $object
  * @param string $filter
  * @param string $property
  *
  * @return string|bool
  */
 public function getImageUrl($object, $filter, $property)
 {
     if (!$this->is_uploaded($object, $property)) {
         return;
     }
     $originalFilename = $this->uploader->asset($object, $property);
     return $this->imagine->filter($originalFilename, $filter);
 }
Example #2
0
 public function save(Image $image)
 {
     $this->em->persist($image);
     $this->vich_uploader->asset($image, 'file');
     /** @var File $uploaded_file */
     $uploaded_file = $image->getFile();
     $this->update_exif($image);
     $this->update_tags($image);
     $this->em->flush();
     $filepath = $this->getFilepath($image);
     $response = array('files' => array(array('name' => $uploaded_file->getFilename(), 'size' => filesize($filepath), 'url' => $this->router->generate('image.show', array('album' => $image->getAlbum()->getSlug(), 'id' => $image->getId())), 'thumbnailUrl' => $this->liip_helper->filter($this->vich_uploader->asset($image, 'file'), 'list'), 'deleteUrl' => $this->router->generate('image.delete', array('id' => $image->getId())), 'deleteType' => 'POST')));
     return new Response(json_encode($response));
 }
Example #3
0
 /**
  * Generates a display URL from the given image.
  *
  * @param MediaInterface $file
  * @param array          $options
  * @param Boolean|string $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
  *
  * @return string The generated URL
  */
 protected function displayUrl(MediaInterface $file, array $options = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     $urlSafePath = $this->mediaManager->getUrlSafePath($file);
     if ($this->imagineHelper && isset($options['imagine_filter']) && is_string($options['imagine_filter'])) {
         return $this->imagineHelper->filter($urlSafePath, $options['imagine_filter'], !empty($options['runtime_config']) ? $options['runtime_config'] : array());
     }
     return $this->generator->generate('cmf_media_image_display', array('path' => $urlSafePath), $referenceType);
 }
Example #4
0
 public function testProxyCallToCacheManagerOnFilter()
 {
     $expectedPath = 'thePathToTheImage';
     $expectedFilter = 'thumbnail';
     $expectedCachePath = 'thePathToTheCachedImage';
     $cacheManager = $this->createCacheManagerMock();
     $cacheManager->expects($this->once())->method('getBrowserPath')->with($expectedPath, $expectedFilter)->will($this->returnValue($expectedCachePath));
     $helper = new ImagineHelper($cacheManager);
     $this->assertEquals($expectedCachePath, $helper->filter($expectedPath, $expectedFilter));
 }
 /**
  * @param PreSerializeEvent $event
  */
 public function onPerSerializeGlavwebMediaFile(PreSerializeEvent $event)
 {
     $entity = $event->getObject();
     $type = $event->getType();
     $className = $type['name'];
     $request = $this->requestStack->getCurrentRequest();
     $reflectionClass = new \ReflectionClass($className);
     $media = array();
     $classProperties = $reflectionClass->getProperties();
     foreach ($classProperties as $property) {
         $uploadableFieldAnnotation = $this->annotationsReader->getPropertyAnnotation($property, 'Glavweb\\UploaderBundle\\Mapping\\Annotation\\UploadableField');
         if ($uploadableFieldAnnotation) {
             /** @var ImagineFilters $imagineFiltersAnnotation */
             $imagineFiltersAnnotation = $this->annotationsReader->getPropertyAnnotation($property, 'Glavweb\\CoreBundle\\Mapping\\Annotation\\ImagineFilters');
             if (!$imagineFiltersAnnotation) {
                 continue;
             }
             $imagineFilterProperty = $imagineFiltersAnnotation->getProperty();
             $getter = 'get' . ucfirst($property->getName());
             $items = $entity->{$getter}();
             if (!is_array($items) && !$items instanceof \Traversable) {
                 continue;
             }
             /** @var Media $item */
             foreach ($items as $item) {
                 $originUrl = null;
                 $thumbnails = [];
                 if ($item->getContentPath()) {
                     $originUrl = $this->mediaHelper->getContentPath($item);
                     foreach ($imagineFiltersAnnotation->getFilters() as $filter) {
                         $thumbnails[$filter] = $this->imagineHelper->filter($originUrl, $filter);
                     }
                 }
                 if ($request) {
                     $originUrl = $request->getSchemeAndHttpHost() . $originUrl;
                 }
                 $media[] = array('originUrl' => $originUrl, 'thumbnails' => $thumbnails, 'name' => $item->getName(), 'description' => $item->getDescription());
             }
             $entity->{$imagineFilterProperty} = $media;
         }
     }
 }