/** * Push a local image/variation to the remote. * * If it is not hydrated this function will throw an exception * * @param Image $image * @param bool $overwrite * * @return $this * * @throws ImageManagerException * @throws ObjectAlreadyExistsException * @throws \Exception */ public function push(Image $image, $overwrite = true) { if (!$image->isHydrated() && $image instanceof ImageVariation) { // A pull on a variation will check if the variation exists, if not create it $this->pull($image); } if (!$image->isHydrated()) { throw new ImageManagerException(self::ERR_NOT_HYDRATED); } if (!$overwrite && $this->tagExists($image->getKey()) === true) { throw new ObjectAlreadyExistsException(self::ERR_ALREADY_EXISTS); } $adapter = $this->filesystem->getAdapter(); if ($adapter instanceof MetadataSupporter) { $metadata = []; if ($image->getMimeType()) { // Set image ContentType on remote filesystem $metadata['ContentType'] = $image->getMimeType(); } $adapter->setMetadata($image->getKey(), $metadata); } // Retrieve source image metadata $metadata = null; if (!$image instanceof ImageVariation) { $image_manipulation = new ImageInspector(); $metadata = $image_manipulation->getImageMetadata($image); } try { $this->filesystem->write($image->getKey(), $image->getData(), $overwrite); $image->__friendSet('persistent', true); $this->tag($image->getKey(), $metadata); } catch (FileAlreadyExists $e) { $this->tag($image->getKey(), $metadata); throw new ObjectAlreadyExistsException(self::ERR_ALREADY_EXISTS); } return $this; }
public function testMetadataRetrieval() { $inspector = new ImageInspector(); $fn = __DIR__ . '/../Resources/image.png'; $im = new ImageManager(new Filesystem(new LocalAdapter(static::$tmp_dir . 'remote')), new EphemeralCachePool(), [], true); $image = $im->loadFromFile($fn, self::TEST_KEY); $im->push($image); $metadata = $inspector->getImageMetadata($image); $this->assertEquals($metadata->getFormat(), ImageFormat::PNG()); $this->assertEquals($metadata->getDimensions(), new ImageDimensions(300, 300)); $this->assertEquals($metadata->getResolution(), new ImageDimensions(72, 72)); $this->assertEquals($metadata->getOrientation(), ImageOrientation::LANDSCAPE()); }