Exemplo n.º 1
0
 /**
  * Get variation or image key.
  *
  * @param bool $parent
  *
  * @return string
  */
 public function getKey($parent = false)
 {
     if ($parent) {
         return parent::getKey();
     } else {
         // TODO: add a configurable naming scheme here
         return parent::getKey() . '~' . $this;
     }
 }
Exemplo n.º 2
0
 /**
  * @param Image $image
  *
  * @return ImageMetadata
  */
 public function getImageMetadata(Image $image)
 {
     if (!$image->isHydrated()) {
         throw new ImageManagerException(ImageManager::ERR_NOT_HYDRATED);
     }
     if ($image instanceof ImageVariation) {
         throw new ImageManagerException(self::ERR_SOURCE_IMAGE);
     }
     $metadata = new ImageMetadata();
     $data_inspector = new DataInspector();
     $data = $image->getData();
     if ($data_inspector->isPdf($data)) {
         $format = ImageFormat::PDF();
     } else {
         $format = $data_inspector->getImageFormat($data);
     }
     $metadata->setMimetype($data_inspector->guessMimeType($data))->setFormat($format)->setResolution($this->getImageResolution($image))->setOrientation($this->getImageOrientation($image))->setDimensions($this->getImageDimensions($image));
     return $metadata;
 }
 /**
  * @medium
  * @dataProvider cacheProvider
  *
  * @param array $cache
  */
 public function testRemote($cache)
 {
     $fn = __DIR__ . '/../Resources/image.png';
     $im = new ImageManager(new Filesystem(new LocalAdapter(static::$tmp_dir . 'remote')), $cache);
     $image_a = $im->loadFromFile($fn, self::TEST_KEY);
     $this->assertTrue($image_a->isHydrated());
     $this->assertFalse($image_a->isPersistent());
     $this->assertFalse($im->exists($image_a));
     $im->push($image_a);
     $this->assertTrue($im->exists($image_a));
     $this->assertTrue($image_a->isPersistent());
     $image_b = new Image(self::TEST_KEY);
     $this->assertFalse($image_b->isHydrated());
     $this->assertFalse($image_b->isPersistent());
     $im->pull($image_b);
     $this->assertTrue($image_b->isHydrated());
     $this->assertTrue($image_b->isPersistent());
     $im->save($image_b, self::$tmp_dir . 'local/pushed_and_pulled.png');
     $im->remove($image_b);
     $this->assertFalse($im->exists($image_a));
 }
Exemplo n.º 4
0
 /**
  * Check with the filesystem if the image exists and update the image key cache.
  *
  * @param Image $image
  *
  * @return bool
  */
 protected function validateTag(Image $image)
 {
     $exists = $this->filesystem->has($image->getKey());
     $this->setImageExists($image, $exists);
     return $exists;
 }