/**
  * Transform image to base 64
  * @param  string $path relative path to image from bundle directory
  * @return string       base64 encoded image
  */
 public function image64($path)
 {
     $file = new File($path, false);
     if (!$file->isFile() || 0 !== strpos($file->getMimeType(), 'image/')) {
         return;
     }
     $binary = file_get_contents($path);
     return sprintf('data:image/%s;base64,%s', $file->guessExtension(), base64_encode($binary));
 }
 public function delete(Media $media, $flush = true)
 {
     $em = $this->entityManager;
     $fs = new Filesystem();
     $file_path = $this->uploadDir . $media->getUri();
     try {
         $file = new File($file_path);
         if ($file->isFile() && $file->isWritable()) {
             $fs->remove($file_path);
         }
     } catch (FileNotFoundException $e) {
     }
     $em->remove($media);
     if ($flush) {
         $em->flush();
     }
 }