Returns a thumbnail of the given asset with the specified dimensions.

@param AssetInterface $asset The asset to render a thumbnail for
@param ThumbnailConfiguration $configuration
@return \Neos\Media\Domain\Model\Thumbnail The thumbnail or NULL
188954
public function findOneByAssetAndThumbnailConfiguration(AssetInterface $asset, ThumbnailConfiguration $configuration)
    {
        /**
         * @var $query \Doctrine\ORM\Query
         */
        $query = $this->entityManager->createQuery('SELECT t FROM Neos\Media\Domain\Model\Thumbnail t WHERE t.originalAsset = :originalAsset AND t.configurationHash = :configurationHash');
        $query->setParameter('originalAsset', $this->persistenceManager->getIdentifierByObject($asset));
        $query->setParameter('configurationHash', $configuration->getHash());

        $query->setMaxResults(1);
        $result = $query->getOneOrNullResult();

        return $result;
    }
11844
public function getAsset($assetType, $assetHandle)
    {
        return isset($this->assets[$assetType][$assetHandle]) ? $this->assets[$assetType][$assetHandle] : null;
    }
740776
public function getModuleForAsset(AssetInterface $asset)
    {
        $sourceRoot = $asset->getSourceRoot();
        $bundleName = $this->bundleMap[$sourceRoot];
        if (!isset($bundleName)) {
            throw new \Exception('Could not map the asset to a bundle');
        }

        return $bundleName . '.templates';
    }
408602
public function createImageVariantAction(ImageVariant $asset)
    {
        if ($this->persistenceManager->isNewObject($asset)) {
            $this->assetRepository->add($asset);
        }

        $propertyMappingConfiguration = new PropertyMappingConfiguration();
        // This will not be sent as "application/json" as we need the JSON string and not the single variables.
        return json_encode($this->entityToIdentityConverter->convertFrom($asset, 'array', [], $propertyMappingConfiguration));
    }
157683
public function getEmbeddedAsset(Asset $asset)
	{
		$embeddedAsset = null;

		if ($asset->kind === Asset::KIND_JSON)
		{
			try
			{
				// Note - 2018-05-09
				// As of Craft 3.0.6 this can be replaced with $asset->getContents()
				// This version was released on 2018-05-08 so need to wait for majority adoption
				$fileContents = stream_get_contents($asset->getStream());
				$decodedJson = Json::decodeIfJson($fileContents);

				if (is_array($decodedJson))
				{
					$embeddedAsset = $this->createEmbeddedAsset($decodedJson);
				}
			}
			catch (Exception $e)
			{
				// Ignore errors and assume it's not an embedded asset
				$embeddedAsset = null;
			}
		}

		return $embeddedAsset;
	}
70212
public function getImageConfig($imageType, $size, $property)
	{
		$config = $this->getConfigPrefix().'images.' . $imageType . '.';
		if ($size == 'original')
		{
			$config .= 'original.';
		}
		elseif (!is_null($size))
		{
			$config .= 'sizes.' . $size . '.';
		}
		$config .= $property;
		return \Config::get($config);
	}
326653
public function generateThumbnailLink(AssetContainer $file, $width, $height)
    {
        $thumbnail = $this->generateThumbnail($file, $width, $height);

        return $this->generateLink($thumbnail);
    }
95733
protected function getPathFromConfiguration($path, ConfigurationInterface $configuration)
    {
        if ($configuration->hasRelativePath()) {
            return $configuration->getRelativePathToFile($path);
        }

        if ($configuration->hasPublicURL()) {
            return $configuration->getPublicURLToFile($path);
        }

        throw new \InvalidArgumentException('Thumbnail configuration doesn\'t support Paths or URLs');
    }
260893
public function guess (Asset $asset) : string
    {
        try
        {
            $predefinedType = self::$mimeTypes[$asset->getFileType()] ?? null;

            if (null !== $predefinedType)
            {
                return $predefinedType;
            }

            $filePath = $this->namespaceRegistry->getFilePath($asset);
            return $this->coreGuesser->guess($filePath);
        }
        catch (AssetsException | Exception $e)
        {
            return "application/octet-stream";
        }
    }
795753
public static function getImg($original, $width = 0, $height = 0, $default = true, $mode = self::THUMB_MODE_CUT)
    {
        $assetUrl = Yii::$app->getAssetManager()->getPublishedUrl('@vendor/jonneyless/yii2-admin-asset/statics');

        if(!file_exists($assetUrl)){
            Yii::$app->getAssetManager()->publish('@vendor/jonneyless/yii2-admin-asset/statics');
        }

        if(substr($original, 0, 4) == 'http'){
            return $original;
        }

        $originalStatic = Folder::getStatic($original);

        if(!file_exists($originalStatic) || is_dir($originalStatic)){
            if($default){
                if($default === true){
                    return Url::getFull($assetUrl . '/img/default.jpg');
                }else{
                    return Url::getStatic($default);
                }
            }else{
                return '';
            }
        }

        list($oWidth, $oHeight) = getimagesize($originalStatic);

        if($width >= $oWidth && $height >= $oHeight){
            return Url::getStatic($original);
        }

        if($mode == self::THUMB_MODE_ADAPT){
            if($width > 0 && $height > 0){
                $scale = min($width / $oWidth, $height / $oHeight);
            }else if($width == 0){
                $scale = $height / $oHeight;
            }else if($height == 0){
                $scale = $width / $oWidth;
            }

            $width = intval($oWidth * $scale);
            $height = intval($oHeight * $scale);

            $mode = ManipulatorInterface::THUMBNAIL_OUTBOUND;
        }else{
            if($width == 0){
                return Url::getStatic($original);
            }

            if($height == 0){
                $height = intval(($oHeight * $width) / $oWidth);
            }

            $mode = $mode == self::THUMB_MODE_CUT ? ManipulatorInterface::THUMBNAIL_OUTBOUND : ManipulatorInterface::THUMBNAIL_INSET;
        }

        $pathInfo = pathinfo($original);

        if($pathInfo['dirname'] == UPLOAD_FOLDER){
            $thumbFolder = THUMB_FOLDER;
        }else{
            $thumbFolder = str_replace(UPLOAD_FOLDER . '/', THUMB_FOLDER . '/', $pathInfo['dirname']);
        }

        $thumb = $thumbFolder . '/' . $pathInfo['filename'] . '_' . $width . 'x' . $height . '.' . $pathInfo['extension'];

        $thumbStatic = Folder::getStatic($thumb);

        if(!file_exists($thumbStatic)){
            Folder::mkdir(Folder::getStatic($thumbFolder));

            YiiImage::thumbnail($originalStatic, $width, $height, $mode)
                ->interlace(ImageInterface::INTERLACE_LINE)
                ->save($thumbStatic, ['quality' => 100]);
        }

        return Url::getStatic($thumb);
    }
528190
public function getProviderIconToSize(EmbeddedAsset $embeddedAsset, int $size)
	{
		return is_array($embeddedAsset->providerIcons) ?
			$this->_getImageToSize($embeddedAsset->providerIcons, $size) : null;
	}
518539
public function getUsageReferences(AssetInterface $asset)
    {
        $assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset);
        if (isset($this->firstlevelCache[$assetIdentifier])) {
            return $this->firstlevelCache[$assetIdentifier];
        }

        $relatedNodes = array_map(function (NodeData $relatedNodeData) use ($asset) {
            return new AssetUsageInNodeProperties($asset,
                $relatedNodeData->getIdentifier(),
                $relatedNodeData->getWorkspace()->getName(),
                $relatedNodeData->getDimensionValues(),
                $relatedNodeData->getNodeType()->getName()
            );
        }, $this->getRelatedNodes($asset));

        $this->firstlevelCache[$assetIdentifier] = $relatedNodes;
        return $this->firstlevelCache[$assetIdentifier];
    }
283899
public function renderAction(ComponentInterface $component, array $config, ContentInterface $content)
    {
        //
        // Data validation
        //
        if (!$component->getData('text')) {
            $this->container->get('logger')->warning(
                'Incomplete text component, "text" field has to be fullfilled.',
                array(
                    'component_id' => $component->getId(),
                    'content_class' => get_class($content),
                    'content_id' => $content->getId()
                )
            );

            return new Response('');
        }

        $templateParameters = array(
            'config' => $config,
            'content' => $content,
        );

        //
        // Medias
        //
        $templateParameters['images'] = (new EntityCollection((array) $component->getData('images')))
            ->map(function ($imageId) {
                return $this->get('synapse.image.loader')->retrieve($imageId);
            })
            ->filter(function ($image) {
                return (bool) $image;
            })
            ->map(function (ImageInterface $image) use ($config) {
                return $image->setDefaultFormat(
                    empty($config['images']['format']) ? null : $config['images']['format']
                );
            })
        ;
        if (!$config['images']['multiple']) {
            $templateParameters['image'] = $templateParameters['images']->first();
        }

        //
        // Resolution
        //
        return $this->get('synapse')
            ->createDecorator($component)
            ->decorate($templateParameters)
        ;
    }
1053478
protected function assetBaseUrl($plugin, $asset)
    {
        $dir  = dirname($asset);
        $path = !empty($dir) && $dir != '.' ? "/$dir" : null;

        return $this->Url->assetUrl($plugin . $path);
    }
426555
public function getAssetFile($type, $assetName)
    {
        if (!$this->hasAsset($type, $assetName)) {
            return false;
        }
    
        // Sort the files by dependnecies
        $file = $this->assets[$type][$assetName];
    
        return $file;
    }
1280364
public static function createAssetOptions(array $config, $assetType)
    {
        $options = array();

        foreach ($config as $key => $value) {
            if (0 === strpos($key, $assetType.'-')) {
                $key = substr($key, \strlen($assetType) + 1);
                $options[$key] = $value;
            }
        }

        return $options;
    }
1134741
public function in(AssetManagerInterface $assetManager)
    {
        // Setup defaults.
        $assetManager->singleton(['dispatcher' => 'Proem\Dispatch\Dispatcher']);

        // Trigger an event allowing client code to override defaults.
        $assetManager->resolve('eventManager')->trigger(
            new Event('proem.in.init.dispatch'),
            function ($responseEvent) use ($assetManager) {
                // Check for a customized Dispatch\Dispatcher.
                if ($responseEvent instanceof Event && $responseEvent->has('dispatcherAsset')) {
                    $assetManager->overrideAsSingleton('dispatcher', $responseEvent->get('dispatcherAsset'));
                }
            }
        );

        // Trigger an event allowing client code to override the way the dispatcher is called.
        $assetManager->resolve('eventManager')->trigger(
            new Event('proem.in.dispatch'),
            function ($responseEvent) use ($assetManager) {
                // Check for a customised dispatch handler.
                if ($responseEvent instanceof Event && $responseEvent->has('dispatchHandler') && $responseEvent->get('dispatcherHandler') instanceof \Closure) {
                    $action = $responseEvent->get('dispatcherHandler');
                    $action($assetManager->resolve('request'));
                } else {
                    // Dispatch using the default handler.
                    $assetManager->resolve('dispatcher')->process($assetManager->resolve('request'));
                }
            }
        );
    }