Generates a thumb for the given media.

@param MediaInterface $media
@return string
422283
public function generateThumbUrl(MediaInterface $media)
    {
        $path = null;

        if ($media->getType() === MediaTypes::IMAGE) {
            $path = $this->cacheManager->getBrowserPath($media->getPath(), 'media_thumb');
        } else {
            $path = $this->generateFileThumb($media);
        }

        if (null === $path) {
            $path = '/bundles/ekynamedia/img/file.jpg';
        }

        return $path;
    }
234769
public function sourceUrl($media)
    {
        return new \Twig_Markup(
            $this->pool->getProvider($media->getProvider())->getUrl($media),
            'utf8'
        );
    }
1198871
protected function generateBinaryFromRequest(MediaInterface $media)
    {
        if (!$media->getContentType()) {
            throw new \RuntimeException(
                'You must provide the content type value for your media before setting the binary content'
            );
        }

        $request = $media->getBinaryContent();

        if (!$request instanceof Request) {
            throw new \RuntimeException('Expected Request in binary content');
        }

        $content = $request->getContent();

        // create unique id for media reference
        $guesser = ExtensionGuesser::getInstance();
        $extension = $guesser->guess($media->getContentType());

        if (!$extension) {
            throw new \RuntimeException(
                sprintf('Unable to guess extension for content type %s', $media->getContentType())
            );
        }

        $handle = tmpfile();
        fwrite($handle, $content);
        $file = new ApiMediaFile($handle);
        $file->setExtension($extension);
        $file->setMimetype($media->getContentType());

        $media->setBinaryContent($file);
    }
469383
private function saveFile(MediaInterface $media)
    {
        $file = $media->getFile();

        $fileInfo = new FileInfo($file);
        $type = $fileInfo->getType();

        $media->setType($type);

        if ($media->getName() === null) {
            $media->setName($fileInfo->getName());
            $media->setAlt($fileInfo->getName());
        }

        $media
            ->setMimeType($fileInfo->getMimeType())
            ->setExtension($fileInfo->getExtension())
            ;

        if (!$this->createReference($media)) {
            return false;
        }

        $key = $this->originalDir.'/'.$media->getReference();
        $this->filesystemManipulator->save($key, $file->getPathname());

        $this->setSizeWidthAndHeight($media);

        $media->setFile();

        if ($this->limit === null || $media->getType() !== $media::IMAGE) {
            return $media;
        }

        // resize if image > limit
        if ($media->getWidth() > $this->limit || $media->getHeight() > $this->limit) {
            $resize = new Resize($this, $media);
            $resize->setTargetSize($this->limit, $this->limit);
            $resize->apply();
        }

        return $media;
    }
1369069
public function getPath(MediaInterface $media, $alias = null)
    {
        return $this->filesystemManipulator->path($this->getAliasAndKey($media, $alias));
    }
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;
    }
198163
public function removeMedia(MediaInterface $media)
    {
        if ($this->medias->contains($media)) {
            $this->medias->removeElement($media);
        }
        return $this;
    }
793085
public function get_thumbnail($filepath, $thumbsize) {
        global $CFG;

        $filepath = trim($filepath, '/');
        $origfile = $this->get_rootpath() . $filepath;
        // As thumbnail filename we use original file content hash.
        if (!$this->is_in_repository($filepath) || !($filecontents = @file_get_contents($origfile))) {
            // File is not found or is not readable.
            return null;
        }
        $filename = file_storage::hash_from_string($filecontents);

        // Try to get generated thumbnail for this file.
        $fs = get_file_storage();
        if (!($file = $fs->get_file(SYSCONTEXTID, 'repository_filesystem', $thumbsize, $this->id, '/' . $filepath . '/',
                $filename))) {
            // Thumbnail not found . Generate and store thumbnail.
            require_once($CFG->libdir . '/gdlib.php');
            if ($thumbsize === 'thumb') {
                $size = 90;
            } else {
                $size = 24;
            }
            if (!$data = generate_image_thumbnail_from_string($filecontents, $size, $size)) {
                // Generation failed.
                return null;
            }
            $record = array(
                'contextid' => SYSCONTEXTID,
                'component' => 'repository_filesystem',
                'filearea' => $thumbsize,
                'itemid' => $this->id,
                'filepath' => '/' . $filepath . '/',
                'filename' => $filename,
            );
            $file = $fs->create_file_from_string($record, $data);
        }
        return $file;
    }
523660
protected function fixFilename(MediaInterface $media)
    {
        if ($media->getBinaryContent() instanceof UploadedFile) {
            $media->setName($media->getName() ?: $media->getBinaryContent()->getClientOriginalName());
            $media->setMetadataValue('filename', $media->getBinaryContent()->getClientOriginalName());
        } elseif ($media->getBinaryContent() instanceof File) {
            $media->setName($media->getName() ?: $media->getBinaryContent()->getBasename());
            $media->setMetadataValue('filename', $media->getBinaryContent()->getBasename());
        }

        // this is the original name
        if (!$media->getName()) {
            throw new \RuntimeException('Please define a valid media\'s name');
        }
    }
691194
public function getMediaUrl(Media $media, $dispositionType = null)
    {
        $url = $media->getUrl();

        if (ResponseHeaderBag::DISPOSITION_INLINE === $dispositionType) {
            $url .= (false === strpos($url, '?') ? '?inline=1' : '&inline=1');
        } elseif (ResponseHeaderBag::DISPOSITION_ATTACHMENT === $dispositionType) {
            $url .= (false === strpos($url, '?') ? '?inline=0' : '&inline=0');
        }

        return $url;
    }
923115
public function get_thumb( $object ) {
		$thumbnail = '';

		if ( $this->field->options( 'show_thumbnails' ) ) {
			// Set thumbnail if the options is true
			$thumbnail = $this->field->options( 'query_users' )
				? get_avatar( $object->ID, 25 )
				: get_the_post_thumbnail( $object->ID, array( 50, 50 ) );
		}

		return $thumbnail;
	}
295115
private function getImageUrl($media, $locale)
    {
        $mediaApi = new Media($media, $locale);
        $this->mediaManager->addFormatsAndUrl($mediaApi);
        $formats = $mediaApi->getThumbnails();

        if (!isset($formats[$this->searchImageFormat])) {
            $this->logger->warning(sprintf(
                'Media with ID "%s" does not have thumbnail format "%s". This thumbnail would be used by the search results.',
                $media->getId(),
                $this->searchImageFormat
            ));

            return;
        }

        return $formats[$this->searchImageFormat];
    }
602989
public function save(MediaInterface $media): MediaInterface
    {
        $data = $this->serializer()->serialize($media);

        if ($media->getId() !== 0) {
            $this->shopware()
                 ->put('/api/media/'.(string)$media->getId(), [], $data);
        } else {
            $response = $this->shopware()->post('/api/media', [], $data);
            $data     = json_decode((string)$response->getBody(), true);
            $media->setId((int)$data['data']['id']);
        }

        return $media;
    }
243199
public function fetchTemporaryThumbnail ($mediaID, $into = null)
    {
        return new Downloaded\Thumbnail($mediaID, $this->doTemporaryFetchToStream($mediaID, $into));
    }
768356
public function getMediaUrl($mediaId, $format)
    {
        $media = $this->getMedia($mediaId);

        if ($media) {
            return $this->displayMediaManager->getMediaFormatUrl($media, $format);
        }

        return '';
    }
1071428
public static function thumbit($thumb)
	{
		$dot = strrpos($thumb, '.') + 1;
		$ext = substr($thumb, $dot);

		return preg_replace('#\.[^.]*$#', '', $thumb) . '_thumb.' . $ext;
	}
1340846
protected function generateMediaLinks(MediaInterface $media) {
    $media_type = $this->entityTypeManager->getStorage('media_type')->load($media->bundle());

    $type_configuration = $media_type->get('source_configuration');

    $links = [];

    $update_route_name = 'islandora.media_source_update';
    $update_route_params = ['media' => $media->id()];
    if ($this->accessManager->checkNamedRoute($update_route_name, $update_route_params, $this->account)) {
      $edit_media_url = Url::fromRoute($update_route_name, $update_route_params)
        ->setAbsolute()
        ->toString();
      $links[] = "<$edit_media_url>; rel=\"edit-media\"";
    }

    if (!isset($type_configuration['source_field'])) {
      return $links;
    }
    $source_field = $type_configuration['source_field'];

    if (empty($source_field) ||
        !$media->hasField($source_field)
    ) {
      return $links;
    }

    // Collect file links for the media.
    foreach ($media->get($source_field)->referencedEntities() as $referencedEntity) {
      if ($referencedEntity->access('view')) {
        $file_url = $referencedEntity->url('canonical', ['absolute' => TRUE]);
        $links[] = "<$file_url>; rel=\"describes\"; type=\"{$referencedEntity->getMimeType()}\"";
      }
    }

    return $links;
  }