@param string $originalImageHtml
@param array  $attributesFilters

@return \DOMElement|string

@throws \Sparwelt\ImgixLib\Exception\TransformationException
342614
public function transformImage($originalImageHtml, array $attributesFilters = [])
    {
        $dom = new \DOMDocument();

        // mute "htmlParseEntityRef: no name in Entity" warning generated by & and &amp;
        @$dom->loadHTML('<?xml encoding="utf-8"?>'.$originalImageHtml);
        if (0 === $dom->getElementsByTagName('img')->length) {
            throw new TransformationException(sprintf('Unable to parse img element: %s', $originalImageHtml));
        }

        $image = $dom->getElementsByTagName('img')->item(0);

        // apply the specified filters
        $originalImageUrl = $image->hasAttribute('src') ? trim($image->getAttribute('src')) : null;
        $processedAttributes = [];
        if (!empty($originalImageUrl) && false === strpos($originalImageUrl, 'data:image/')) {
            try {
                $elementFilters = $attributesFilters;

                // consider html 'width' and 'height' attributes for filter generation
                if (isset($elementFilters['src']) && is_array($elementFilters['src'])) {
                    if ($image->hasAttribute('width') && '' !== $image->getAttribute('width')) {
                        $elementFilters['src']['w'] = $image->getAttribute('width');
                    }
                    if ($image->hasAttribute('height') && '' !== $image->getAttribute('height')) {
                        $elementFilters['src']['h'] = $image->getAttribute('height');
                    }
                }

                foreach ($elementFilters as $attributeName => $filters) {
                    $attributeValue = $this->attributeGenerator->generateAttributeValue($originalImageUrl, $filters);
                    if ('' !== $attributeValue) {
                        $image->setAttribute($attributeName, $attributeValue);
                        $processedAttributes[] = $attributeName;
                    }
                }
            } catch (ResolutionException $e) {
            }
        }

        // apply the cdn domain on the remaining attributes
        foreach ($image->attributes as $attribute) {
            if (!in_array($attribute->name, $processedAttributes)) {
                $this->applyCdnDomain($attribute);
            }
        }

        return $this->renderer->render($image);
    }
1320298
protected function parseAttributeFilters(array &$parsedRules, $attribute, $filters)
    {
        foreach (explode('|', $filters) as $filter) {
            $parsedFilter = $this->parseRule($filter);

            if ( ! empty($parsedFilter)) {
                $parsedRules[$attribute][] = $parsedFilter;
            }
        }
    }
1033250
public function generateUrl($originalUrl, array $filterParams = [])
    {
        if (empty($originalUrl)) {
            throw new ResolutionException('Empty url');
        }

        $cdn = $this->cdnSelector->getCdnForImage($originalUrl);

        $queryParams = $cdn->isGenerateFilterParams() ? array_merge($cdn->getDefaultQueryParams(), $filterParams) : [];

        if (Utils::isMatrix($queryParams)) {
            throw new ConfigurationException(
                sprintf('Monodimensional array expected, matrix given as query parameters: %s', serialize($queryParams))
            );
        }

        $cdnId = spl_object_hash($cdn);
        $shardStrategy = $this->translateShardStrategy($cdn->getShardStrategy());

        if (!isset($this->builders[$cdnId])) {
            try {
                $this->builders[$cdnId] = new UrlBuilder(
                    $cdn->getCdnDomains(),
                    $cdn->isUseSsl(),
                    $cdn->getSignKey(),
                    $shardStrategy,
                    false
                );
            } catch (\InvalidArgumentException $e) {
                throw new ResolutionException($e->getMessage());
            }
        }

        $imagePath = parse_url($originalUrl, PHP_URL_PATH);

        if (false === $imagePath) {
            throw new ResolutionException(sprintf('Malformed image url %s', $originalUrl));
        }

        return $this->builders[$cdnId]->createURL(parse_url($originalUrl, PHP_URL_PATH), $queryParams);
    }
1202894
public function getAttributesHTML($attributes = null)
    {
        $exclude = null;

        if (is_string($attributes)) {
            $exclude = func_get_args();
        }

        if (!$attributes || is_string($attributes)) {
            $attributes = $this->getAttributes();
        }

        $attributes = (array) $attributes;

        $attributes = array_filter($attributes, function ($v) {
            return ($v || $v === 0 || $v === '0');
        });

        if ($exclude) {
            $attributes = array_diff_key(
                $attributes,
                array_flip($exclude)
            );
        }

        // Create markup
        $parts = array();

        foreach ($attributes as $name => $value) {
            if ($value === true) {
                $parts[] = sprintf('%s="%s"', $name, $name);
            } else {
                $strValue = Convert::raw2att($value);
                if (!is_string($strValue)) {
                    $strValue = json_encode($strValue);
                }
                $parts[] = sprintf('%s="%s"', $name, $strValue);
            }
        }

        return implode(' ', $parts);
    }
342637
public function generateAttributeValue($originalUrl, $filtersOrConfigurationKey = [], array $extraFilters = [])
    {
        $filters = $this->prepareFilterParams($filtersOrConfigurationKey, $extraFilters);

        return $this->attributeGenerator->generateAttributeValue($originalUrl, $filters);
    }
628664
public function transformImage($file, $transform, $transformDefaults = null, $configOverrides = null)
    {
        $image = Plugin::$plugin->imager->transformImage($file, $transform, $transformDefaults, $configOverrides);

        return $image;
    }
993158
public static function image($url, $alt = null, $attributes = array(), $secure = null)
    {
        $html = self::getInstance()->html;
        $args = func_get_args();
        return call_user_func_array(array($html, __FUNCTION__), $args);
    }
185455
private static function buildAttributes($htmlAttributes, $ignore = array())
    {
        if (empty($htmlAttributes))
        {
            return '';
        }

        if ($ignore === null) {
            $ignore = array();
        }

        $filtered = array_filter($htmlAttributes, function($key) use ($ignore) {
            return !in_array($key, $ignore);
        }, \ARRAY_FILTER_USE_KEY);

        array_walk($filtered, function(&$value, $key) {
            $value = sprintf('%s="%s"', $key, self::encodeHtmlAttributeString($value));
        });

        return implode(' ', $filtered);
    }
518719
protected function wordMatchSupport( $newTagName, $attributes, $attributeString )
    {
        $ini = eZINI::instance( 'wordmatch.ini' );
        if ( $ini->hasVariable( $newTagName, 'MatchString' ) )
        {
            $matchArray = $ini->variable( $newTagName, 'MatchString' );
            if ( $matchArray )
            {
                foreach ( array_keys( $matchArray ) as $key )
                {
                    $matchString = $matchArray[$key];
                    if (  preg_match( "/$matchString/i", $attributeString ) )
                    {
                        $attributes['class'] = $key;
                        unset( $attributes['style'] );
                    }
                }
            }
        }
        return $attributes;
    }
377025
function imagePathByNode( $contentObjectAttribute, $mainNode )
    {
        $pathString = $mainNode->pathWithNames();
        $pathString = function_exists( 'mb_strtolower' ) ? mb_strtolower( $pathString ) : strtolower( $pathString );

        $ini = eZINI::instance( 'image.ini' );
        $contentImageSubtree = $ini->variable( 'FileSettings', 'PublishedImages' );
        $attributeData = $this->originalAttributeData();
        $attributeID = $attributeData['attribute_id'];
        $attributeVersion = $attributeData['attribute_version'];
        $attributeLanguage = $attributeData['attribute_language'];
        $pathParts = array( eZSys::storageDirectory(), $contentImageSubtree );
        if ( $pathString != '' )
        {
            //Make sure that all folders are smaller than the FS limit
            foreach ( explode( '/', $pathString ) as $folder )
            {
                $pathParts[] = $this->trimToFileSystemFileName( $folder );
            }
        }
        $pathParts[] = $attributeID . '-' . $attributeVersion . '-' . $attributeLanguage;
        $imagePath = implode( '/', $pathParts );
        return $imagePath;
    }
1082071
public static function createElement($tag = '', $attributes1 = [], $attributes2 = [])
    {
        $tag_object = parent::createElement($tag);
        $tag_object->setTag($tag);
        $attributes = $attributes1;
        if (!is_array($attributes1) && strlen($attributes1) > 0) {
            $tag_object->text($attributes1);
            $attributes = $attributes2;
        }
        if (is_array($attributes)) {
            foreach ($attributes as $name => $value) {
                if (method_exists($tag_object, $name)) {
                    if (!is_array($value)) {
                        $value = [$value];
                    }
                    call_user_func_array([$tag_object, $name], $value);
                }
            }
        }

        $tag_object->configDefaults($tag);

        return $tag_object;
    }
349187
public function img($conversion = '', array $extraAttributes = []): string
    {
        if (! (new Image())->canHandleMime($this->mime_type)) {
            return '';
        }

        if (is_array($conversion)) {
            $attributes = $conversion;

            $conversion = $attributes['conversion'] ?? '';

            unset($attributes['conversion']);

            $extraAttributes = array_merge($attributes, $extraAttributes);
        }

        $attributeString = collect($extraAttributes)
            ->map(function ($value, $name) {
                return $name.'="'.$value.'"';
            })->implode(' ');

        if (strlen($attributeString)) {
            $attributeString = ' '.$attributeString;
        }

        $media = $this;

        $viewName = 'image';

        $width = '';

        if ($this->hasResponsiveImages($conversion)) {
            $viewName = config('medialibrary.responsive_images.use_tiny_placeholders')
                ? 'responsiveImageWithPlaceholder'
                : 'responsiveImage';

            $width = $this->responsiveImages($conversion)->files->first()->width();
        }

        return view("medialibrary::{$viewName}", compact(
            'media',
            'conversion',
            'attributeString',
            'width'
        ));
    }
841072
protected function textParsedownElement(array $attributes, $reset = true)
    {
        $text = empty($attributes['title']) ? empty($attributes['alt']) ? $this->get('filename') : $attributes['alt'] : $attributes['title'];

        $element = [
            'name' => 'p',
            'attributes' => $attributes,
            'text' => $text
        ];

        if ($reset) {
            $this->reset();
        }

        return $element;
    }
1128402
protected function searchNodes(Filter\AbstractFilter $filter, $attributes = null, $searchScope = Connection::SEARCH_SCOPE_SUB, $maxResults = 0, $maxFilterTime = 0)
    {
        if ($attributes === null) {
            $attributes = $this->getSearchAttributes();
        }

        return $this->connection->search(
            $filter,
            $this->getSearchBaseDn(),
            $searchScope,
            $attributes,
            null,
            $this->getNodeCollectionClass(),
            $maxResults,
            $maxFilterTime
        );
    }
1326180
protected function _validate($attribute, $rule, $parameters, $value)
    {
        $srcValue = $value;

        if (isset($this->_validators[$rule])) {
            /** @noinspection VariableFunctionsUsageInspection */
            $value = call_user_func_array($this->_validators[$rule], [$value, $parameters]);
        } elseif (function_exists($rule)) {
            $value = call_user_func_array($rule, array_merge([$value], $parameters));
        } else {
            throw new FilterException(['`:name` rule is not be recognized', 'name' => $rule]);
        }

        if ($value === null) {
            if (is_string($this->_messages)) {
                if (strpos($this->_messages, '.') === false) {
                    $file = '@manaphp/Http/Validator/Messages/' . $this->_messages . '.php';
                } else {
                    $file = $this->_messages;
                }

                if (!$this->filesystem->fileExists($file)) {
                    throw new FilterException(['`:file` rule message template file is not exists', 'file' => $file]);
                }

                /** @noinspection PhpIncludeInspection */
                $this->_messages = require $this->alias->resolve($file);
            }

            if (isset($this->_messages[$rule])) {
                $message = [$this->_messages[$rule]];
            } else {
                $message = [$this->_defaultMessage];
            }

            $message['rule'] = $rule;
            $message['attribute'] = isset($this->_attributes[$attribute]) ? $this->_attributes[$attribute] : $attribute;
            $message['value'] = $srcValue;
            foreach ($parameters as $k => $parameter) {
                $message['parameters[' . $k . ']'] = $parameter;
            }

            throw new FilterException($message);
        }

        return $value;
    }
1107380
protected function checkAttributeFilters(array $attributes)
	{
		foreach ($attributes as $attrConfig)
		{
			if (empty($attrConfig['filterChain']))
			{
				continue;
			}
			foreach ($attrConfig['filterChain'] as $filter)
			{
				if (substr($filter, 0, 1) !== '#' && !in_array($filter, $this->allowedFilters, true))
				{
					throw new RuntimeException("Filter '$filter' is not allowed in media sites");
				}
			}
		}
	}
388250
private function getFilterMethod($transform): string
    {
        /** @var ConfigModel $settings */
        $config = ImagerService::getConfig();

        return ImagerService::$imageDriver === 'imagick' ? ImagerService::$filterKeyTranslate[(string)$config->getSetting('resizeFilter', $transform)] : ImageInterface::FILTER_UNDEFINED;
    }