Creates the images list.

@param object $media The media object
@return array
14256
protected function createImagesList($media)
    {
        $url = $media->thumbnail_url;
        $width = $media->thumbnail_width;
        $height = $media->thumbnail_height;

        return array(
            array(
                'url'    => $url,
                'width'  => $width,
                'height' => $height,
                'area'   => ($width * $height)
            )
        );
    }
1189558
public function newAction($type) {
        $entity = new Media();
        $entity->setMediaType($type);
        $form = $this->createCreateForm($entity);

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
414606
public function prepareMedia(Media $media)
    {
        if (null === $media->getUuid()) {
            $uuid = uniqid();
            $media->setUuid($uuid);
        }

        $content = $media->getContent();
        if (empty($content)) {
            return;
        }

        if (!$content instanceof File) {
            if (!is_file($content)) {
                throw new \RuntimeException('Invalid file');
            }

            $file = new File($content);
            $media->setContent($file);
        }

        $contentType = $this->mimeTypeGuesser->guess($content->getPathname());
        if ($content instanceof UploadedFile) {
            $pathInfo = pathinfo($content->getClientOriginalName());

            if (!array_key_exists('extension', $pathInfo)) {
                $pathInfo['extension'] = $this->extensionGuesser->guess($contentType);
            }

            $media->setOriginalFilename($this->slugifier->slugify($pathInfo['filename']).'.'.$pathInfo['extension']);
            $name = $media->getName();

            if (empty($name)) {
                $media->setName($media->getOriginalFilename());
            }
        }

        $media->setContentType($contentType);
        $media->setFileSize(filesize($media->getContent()));
        $media->setUrl($this->mediaPath . $this->getFilePath($media));
        $media->setLocation('local');
    }
1256404
public function prepareMedia(Media $media)
    {
        $handler = $this->getHandler($media);
        $handler->prepareMedia($media);

        return $this;
    }
1296496
public function getMediaFile()
    {
      $content = $this->client->get($this->media, array(), FALSE);

      $media = new Media;
      $media->setData($content);

      return $media;
    }
1134017
public function resolveMediasFunction($medias, $locale)
    {
        if (0 === count($medias)) {
            return [];
        }

        $ids = [];
        $entities = [];
        $entitiesIndex = [];
        for ($i = 0; $i < count($medias); ++$i) {
            $media = $medias[$i];

            if (is_object($media)) {
                $entities[$i] = $this->resolveMediaObject($media, $locale);
            } else {
                $ids[] = $media;
                $entitiesIndex[$media] = $i;
            }
        }

        if (count($ids) > 0) {
            foreach ($this->mediaManager->getByIds($ids, $locale) as $media) {
                $entities[$entitiesIndex[$media->getId()]] = $media;
            }
        }

        ksort($entities);

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

		return $this;
	}
916275
private function findMediaObjectsForMediaFile(string $file): array
    {
        return DB::table('media')
            ->join('media_file', static function (JoinClause $join): void {
                $join
                    ->on('media_file.m_file', '=', 'media.m_file')
                    ->on('media_file.m_id', '=', 'media.m_id');
            })
            ->join('gedcom_setting', 'media.m_file', '=', 'gedcom_setting.gedcom_id')
            ->where(DB::raw('setting_value || multimedia_file_refn'), '=', $file)
            ->select(['media.*'])
            ->distinct()
            ->get()
            ->map(Media::rowMapper())
            ->all();
    }
1030946
public function loadMedia()
    {
        $files = $this->getMediaFiles();

        foreach ($files as $file) {
            $mediaFile = $this->getCollection()->newMedia();
            $mediaFile->setFile($file);
            $this->appendMediaInCollection($mediaFile);
        }
    }
1224709
public function toArray()
    {
        $result             = parent::toArray();
        $result['mediaId']  = $this->mediaId;
        $result['picUrl']   = $this->picUrl;

        return $result;
    }
881518
private function getSortedMediaTypeList(int $tot): array
    {
        $media = [];
        $c     = 0;
        $max   = 0;

        foreach (self::MEDIA_TYPES as $type) {
            $count = $this->totalMediaTypeQuery($type);

            if ($count > 0) {
                $media[$type] = $count;

                if ($count > $max) {
                    $max = $count;
                }

                $c += $count;
            }
        }

        $count = $this->totalMediaTypeQuery(self::MEDIA_TYPE_UNKNOWN);
        if ($count > 0) {
            $media[self::MEDIA_TYPE_UNKNOWN] = $tot - $c;
            if ($tot - $c > $max) {
                $max = $count;
            }
        }

        if (count($media) > 10 && ($max / $tot) > 0.6) {
            arsort($media);
            $media = array_slice($media, 0, 10);
            $c     = $tot;

            foreach ($media as $cm) {
                $c -= $cm;
            }

            if (isset($media[self::MEDIA_TYPE_OTHER])) {
                $media[self::MEDIA_TYPE_OTHER] += $c;
            } else {
                $media[self::MEDIA_TYPE_OTHER] = $c;
            }
        }

        asort($media);

        return $media;
    }
522404
public function createNew($data)
    {
        if ($data instanceof File) {
            /* @var $data File */

            $media = new Media();
            if (method_exists($media, 'getClientOriginalName')) {
                $media->setName($data->getClientOriginalName());
            } else {
                $media->setName($data->getFilename());
            }
            $media->setContent($data);

            return $media;
        }
    }
541198
public function media($media, $format, $options = [])
    {
        $media = $this->getMedia($media);

        if (null === $media) {
            return '';
        }

        $provider = $this
            ->getMediaService()
            ->getProvider($media->getProviderName());

        $format = $provider->getFormatName($media, $format);

        $options = $provider->getHelperProperties($media, $format, $options);

        return $this->render($provider->getTemplate('helper_view'), [
            'media' => $media,
            'format' => $format,
            'options' => $options,
        ]);
    }
1021889
public function prepareMedia(Media $media)
    {
        if (null == $media->getUuid()) {
            $uuid = uniqid();
            $media->setUuid($uuid);
        }
        $video = new RemoteVideoHelper($media);
        $url = $video->getCode();
        //update thumbnail
        switch ($video->getType()) {
            case 'youtube':
                $code = $this->isolateYoutubeVideoCode($url);
                $video->setThumbnailUrl('http://img.youtube.com/vi/'.$code.'/0.jpg');
                break;
            case 'vimeo':
                $code = $this->isolateVimeoVideoCode($url);
                $xml = simplexml_load_file('http://vimeo.com/api/v2/video/'.$code.'.xml');
                $video->setThumbnailUrl((string) $xml->video->thumbnail_large);
                break;
            case 'dailymotion':
                $code = $this->isolateDailymotionVideoCode($url);
                $json = json_decode(file_get_contents('https://api.dailymotion.com/video/'.$code.'?fields=thumbnail_large_url'));
                $thumbnailUrl = $json->{'thumbnail_large_url'};
                /* dirty hack to fix urls for imagine */
                if (!$this->endsWith($thumbnailUrl, '.jpg') && !$this->endsWith($thumbnailUrl, '.png')) {
                    $thumbnailUrl = $thumbnailUrl.'&ext=.jpg';
                }
                $video->setThumbnailUrl($thumbnailUrl);
                break;
        }
    }
330844
private function getOrCreateMediaRuleToAppendTo($media)
    {
        $lastMediaRule = \end($this->mediaRules);
        if ($lastMediaRule !== false && $media === $lastMediaRule->media) {
            return $lastMediaRule;
        }

        $newMediaRule = (object)[
            'media' => $media,
            'ruleBlocks' => [],
        ];
        $this->mediaRules[] = $newMediaRule;
        return $newMediaRule;
    }
209262
public function getLayoutName($media)
	{
		$layout = null;
		$trace = array();

		foreach ($this as $abstractPage) {
			if ($abstractPage instanceof Template) {
				if ($abstractPage->hasLayout($media)) {
					$layout = $abstractPage->getLayoutName($media);
				}
			}

			$trace[] = (string) $abstractPage;
		}

		return $layout;
	}
884319
protected function orderMedia($media)
    {
        if (null === $this->media_order) {
            /** @var Page $page */
            $page = Grav::instance()['pages']->get($this->getPath());

            if ($page && isset($page->header()->media_order)) {
                $this->media_order = array_map('trim', explode(',', $page->header()->media_order));
            }
        }

        if (!empty($this->media_order) && is_array($this->media_order)) {
            $media = Utils::sortArrayByArray($media, $this->media_order);
        } else {
            ksort($media, SORT_NATURAL | SORT_FLAG_CASE);
        }

        return $media;
    }