Removes the media.

@param MediaInterface $media
@return MediaUpload
198163
public function removeMedia(MediaInterface $media)
    {
        if ($this->medias->contains($media)) {
            $this->medias->removeElement($media);
        }
        return $this;
    }
621183
public function generateAlternatives(MediaInterface $media)
    {
        $filePath = $this->tmpDir . DIRECTORY_SEPARATOR . $media->getFilesystemName();

        foreach ($this->alternativeFormats as $formatName => $format) {
            $alternativeName = $this->generateAlternative($media->getFilesystemName(), $formatName, $format);
            $media->addAlternative($formatName, $alternativeName);
        }

        if (trim($filePath, DIRECTORY_SEPARATOR) != trim($this->tmpDir, DIRECTORY_SEPARATOR)) {
            $this->fileSystem->remove(array($filePath));
        }
    }
1069042
public function getImages(MediaInterface $media, array $filters)
    {
        $key = $media->getImagesCacheKey();
        if (!$images = $this->cache->fetch($key)) {
            $provider = $this->getProvider($media);

            $reference = $provider->getThumb($media);

            $images = [];
            foreach ($filters as $filter) {
                if ($media->getContentType() == 'image/svg+xml') {
                    $images[$filter] = $provider->getUrl($media);
                } else {
                    $images[$filter] = $this->cacheManager->getBrowserPath($reference, $filter);
                }
            }

            $this->cache->save($key, $images, 0);
        }

        return $images;
    }
810937
public function setSizeWidthAndHeight(MediaInterface $media)
    {
        $key = $this->originalDir.'/'.$media->getReference();

        $media->setSize($this->filesystemManipulator->size($key));

        if ($media->getType() === $media::IMAGE) {
            $image = $this->imagine->load(
                $this->filesystemManipulator->read($key)
            );
            $size = $image->getSize();
            $media->setWidth($size->getWidth());
            $media->setHeight($size->getHeight());
        }

        return $this;
    }
679795
public function updateFocus(MediaInterface $media)
    {
        if ($this->angle == 90) {
            $focusLeft = 100 - $media->getFocusTop();
            $focusTop = $media->getFocusLeft();
        } elseif ($this->angle == -90) {
            $focusLeft = $media->getFocusTop();
            $focusTop = 100 - $media->getFocusLeft();
        }

        $media->setFocusLeft($focusLeft);
        $media->setFocusTop($focusTop);
    }
1237794
public function preUpdate(MediaInterface $media)
    {
        $this->cleanTranslations($media);
        $this->uploader->prepare($media);
    }
659724
public function getAliasAndKey(MediaInterface $media, $alias = null)
    {
        $aliasManipulator = $this->aliasManipulatorFactory->setAlias($alias);

        if ($media->getType() === $media::IMAGE) {
            $alias = $aliasManipulator->getAliasName();

            if ($alias !== $this->originalDir) {
                $this->cropImage($media, $aliasManipulator);
            }
        } else {
            $alias = $this->originalDir;
        }

        return $alias.'/'.$media->getReference();
    }
1139846
public function destroy(Admin $admin, Media $media)
    {
        $admin->media()->where($media->getKeyName(), $media->getKey())->first()->delete();

        return intend([
            'url' => route('adminarea.admins.edit', ['admin' => $admin]),
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])],
        ]);
    }
569595
protected function getExtension(MediaInterface $media)
    {
        $ext = $media->getExtension();
        if (!\is_string($ext) || \strlen($ext) < 3) {
            $ext = $this->defaultFormat;
        }

        return $ext;
    }
197939
public function createReference(MediaInterface $media)
    {
        $allowed = false;
        foreach ($this->contexts as $context) {
            if (in_array($media->getExtension(), $context)) {
                $allowed = true;
                break;
            }
        }

        if ($allowed === false) {
            $this->error = array('error.extensionNotAllowed', array('%extension%' => $media->getExtension()));

            return false;
        }

        // secure extension for reference
        if (!in_array($media->getExtension(), $this->trustedExtensions)) {
            $media->setExtension($media->getExtension().'.txt');
            $media->setType($media::OTHER);
        }

        do {
            $media->setReference(sha1(microtime(true).mt_rand()).'.'.$media->getExtension());
        } while ($this->filesystemManipulator->has($this->originalDir.'/'.$media->getReference()));

        return true;
    }
694432
public function addMedia(Media $media)
	{
		$this->media[] = $media;
		$media->addGallery($this);

		return $this;
	}
932256
public function addMedia(Media $media)
    {
        $this->medias->add($media);
        $media->addTweet($this);

        return $this;
    }
357117
public function reset(MediaInterface $media = null, $onlyFocus = false)
    {
        if ($onlyFocus === true) {
            $regex = '#^\d*x\d*_focus/';
        } else {
            $regex = '#^\d*x\d*(_focus)?/';
        }

        $regex .= ($media !== null) ? $media->getReference() : '.*';
        $regex .= '$#';

        foreach ($this->filesystemManipulator->keys() as $file) {
            if (preg_match($regex, $file)) {
                $this->filesystemManipulator->delete($file);
            }
        }
    }
1258127
public function clearMediaCollectionExcept(string $collectionName = 'default', $excludedMedia = [])
    {
        if ($excludedMedia instanceof Media) {
            $excludedMedia = collect()->push($excludedMedia);
        }

        $excludedMedia = collect($excludedMedia);

        if ($excludedMedia->isEmpty()) {
            return $this->clearMediaCollection($collectionName);
        }

        $this->getMedia($collectionName)
            ->reject(function (Media $media) use ($excludedMedia) {
                return $excludedMedia->where('id', $media->id)->count();
            })
            ->each->delete();

        if ($this->mediaIsPreloaded()) {
            unset($this->media);
        }

        return $this;
    }
45860
public function setData(Media $media)
    {
        $this->id = $media->getId();
        $this->title = $media->getTitle();
        $this->setFormats($media->getFormats());
        $this->url = $media->getUrl();
        $this->copyright = $media->getCopyright();

        return $this;
    }
380583
public function removeMedia(Media $media)
	{
		$this->media->removeElement($media);
		$media->removeGallery($this);
	}
1096951
public function process(Media $media)
    {
        if ($this->request->getMethod() == 'POST')
        {
            $this->form->handleRequest($this->request);
            if ($this->form->isValid())
            {
                $file = $this->form->get('media')->getData();
                if (!is_null($file))
                {
                    $media->setMediaType($file->getMimeType());
                    $media->setOriginalName($file->getClientOriginalName());
                    $filename = $this->mediaLibraryService->add($file, $media);
                    if ($filename)
                    {
                        // New media
                        if ($media->getId() == 0)
                        {
                            if (is_a($this->user, 'Symfony\Component\Security\Core\User\UserInterface')
                                    && method_exists($this->user, 'getId'))
                            {
                                $media->setOwnerId($this->user->getId());
                            }
                        }
                        else
                        {
                            // We remove old files
                            $this->mediaLibraryService->remove($media);
                        }

                        // We set new file
                        $media->setFullPath($filename);

                        $em = $this->doctrine->getManager();
                        $em->persist($media);
                        $em->flush();
                        return TRUE;
                    }
                }
            }
        }
        return FALSE;
    }