/**
  * @param Media $media
  * @throws \Exception
  */
 public function generateThumbnails(Media $media)
 {
     $context = $media->getContext();
     if (!array_key_exists($context, $this->contextConfiguration)) {
         throw new \Exception('Supplied context does not exist');
     }
     $formats = $this->contextConfiguration[$context]['formats'];
     $referencePath = $this->locator->getReferencePath($media);
     $referenceBinaryData = $this->filesystem->read($referencePath);
     foreach ($formats as $name => $settings) {
         $path = $this->locator->getThumbnailPath($media, $name);
         $data = $this->generateThumbnail($referenceBinaryData, $settings);
         $this->filesystem->writeContent($path, $data);
     }
 }
 /**
  * @param $media
  * @throws \Exception
  */
 private function saveReference(Media $media)
 {
     $file = $media->getFile();
     $path = $this->locator->getReferencePath($media);
     $this->filesystem->write($path, $file);
 }
 public function mediaPath($media, $format)
 {
     return $format === 'reference' ? $this->locator->getReferencePath($media) : $this->locator->getThumbnailPath($media, $format);
 }