@param ImageInterface $image

@return int|null
161920
private function getOrientation(ImageInterface $image)
    {
        foreach ($this->orientationKeys as $orientationKey) {
            $orientation = $image->metadata()->offsetGet($orientationKey);

            if ($orientation) {
                $image->metadata()->offsetSet($orientationKey, '1');

                return (int) $orientation;
            }
        }

        return null;
    }
851208
public function manipulateImage(ImageInterface $image, ImagePathInterface $path)
    {
        /**
         * @var ImageOptimizerInterface $optimizer
         */
        $optimizer = null;
        if (!empty($this->imageOptimizers[$image->getMimeType()])) {
            // Use the first matching optimizer.
            $optimizer = reset($this->imageOptimizers[$image->getMimeType()]);
        }
        if ($optimizer) {
            $optimizer->optimizeImage($image);
        }
    }
496615
public function getImageCaption($image): ?string
    {
        if (null === ($file = $this->container->get('huh.utils.file')->getFileFromUuid($image))) {
            return null;
        }

        $meta = StringUtil::deserialize($file->getModel()->meta, true);

        if (!isset($meta[$GLOBALS['TL_LANGUAGE']]['caption'])) {
            return null;
        }

        return $meta[$GLOBALS['TL_LANGUAGE']]['caption'];
    }
489578
protected static function ensureImageInterfaceInstance($image)
    {
        if ($image instanceof ImageInterface) {
            return $image;
        }

        if (is_resource($image)) {
            return static::getImagine()->read($image);
        }

        if (is_string($image)) {
            return static::getImagine()->open(Yii::getAlias($image));
        }

        throw new InvalidParamException('File should be either ImageInterface, resource or a string containing file path.');
    }
1008063
public function execute($image)
    {
        $level = $this->argument(0)->between(-100, 100)->required()->value();

        return imagefilter($image->getCore(), IMG_FILTER_CONTRAST, ($level * -1));
    }
1073716
protected function handleImageManipulation(ImageInterface $image, array $data): ImageInterface
    {
        $width = $data['width'];
        $height = $data['height'];

        if (isset($data['dimension'])) {
            $width = $height = $data['dimension'];
        }

        return $image->resize(new Box($width, $height), $data['filter']);
    }
357880
public function getImageInfo($image)
    {
        if ( empty($image) || !file_exists($image))
        {
            throw new \InvalidArgumentException('Image file not found.');
        }

        $pathInfo = pathinfo($image);
        $info     = getimagesize($image);

        if ( !in_array($pathInfo['extension'], $this->types) )
        {
            throw new \InvalidArgumentException('Unsupported image file extension.');
        }

        $info['width']    = $info[0];
        $info['height']   = $info[1];
        $info['ext']      = $info['type'] = $pathInfo['extension'];
        $info['size']     = filesize($image);
        $info['dir']      = $pathInfo['dirname'];
        $info['path']     = str_replace('/', DIRECTORY_SEPARATOR, $image);
        $info['fullname'] = $pathInfo['basename'];
        $info['filename'] = $pathInfo['filename'];
        $info['type']     = ($info['type'] == 'jpg') ? 'jpeg' : $info['type'];

        return $info;
    }
72321
public function applyFilter(Image $image)
    {
        return $image->resize(300, null, function($constraint) {
            $constraint->aspectRatio();
        })->encode('jpg', 40);
    }
98690
private function updateSize(Version $fv, ImageInterface $image)
    {
        $result = false;
        try {
            $size = $image->getSize();
        } catch (Exception $x) {
            $size = null;
        } catch (Throwable $x) {
            $size = null;
        }
        if ($size !== null) {
            $attributeCategory = $fv->getObjectAttributeCategory();
            $atWidth = $attributeCategory->getAttributeKeyByHandle('width');
            if ($atWidth !== null) {
                $fv->setAttribute($atWidth, $size->getWidth());
            }
            $atHeight = $attributeCategory->getAttributeKeyByHandle('height');
            if ($atHeight !== null) {
                $fv->setAttribute($atHeight, $size->getHeight());
            }
            $result = true;
        }

        return $result;
    }
468765
public function apply( $image ) {

        $image->getCore()->sigmoidalContrastImage($this->amount > 0, $this->amount / 4, 0);
        return $image;
    }
404412
public function allocate($image): int {
        if ($image instanceof Image) {
            $image = $image->getResource();
        }

        return imagecolorallocatealpha(
            $image,
            $this->r,
            $this->g,
            $this->b,
            $this->a
        );
    }
1187591
public function getImageSource(ImageInterface $image)
    {
        $path = $this->getAbsolutePath($image->getPath());

        if (!is_file($path)) {
            throw new IOException(sprintf('Not found image source "%s"', $image->getId()));
        }

        return file_get_contents($path);
    }
442860
public function applyToImage(ImagineImageInterface $image)
    {
        $ratioMode = $this->ratioMode ?: ImageInterface::RATIOMODE_INSET;
        return $this->resize($image, $ratioMode, $this->filter);
    }
1092219
private function getImageWidth(Image $image, int $height): int
    {
        return (int)($height * ($image->getWidth() / $image->getHeight()));
    }
814279
public function load(ImageInterface $image, array $options = [])
    {
        $options += [
            'size' => null,
            'position' => 'center',
        ];

        if ('%' === mb_substr($options['size'], -1)) {
            $options['size'] = mb_substr($options['size'], 0, -1) / 100;
        }

        $watermark = $this->imagine->open($this->rootPath.'/'.$options['image']);

        $size = $image->getSize();
        $watermarkSize = $watermark->getSize();

        // If 'null': Downscale if needed
        if (!$options['size'] && ($size->getWidth() < $watermarkSize->getWidth() || $size->getHeight() < $watermarkSize->getHeight())) {
            $options['size'] = 1.0;
        }

        if ($options['size']) {
            $factor = $options['size'] * min($size->getWidth() / $watermarkSize->getWidth(), $size->getHeight() / $watermarkSize->getHeight());

            $watermark->resize(new Box($watermarkSize->getWidth() * $factor, $watermarkSize->getHeight() * $factor));
            $watermarkSize = $watermark->getSize();
        }

        switch ($options['position']) {
            case 'topleft':
                $x = 0;
                $y = 0;
                break;
            case 'top':
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
                $y = 0;
                break;
            case 'topright':
                $x = $size->getWidth() - $watermarkSize->getWidth();
                $y = 0;
                break;
            case 'left':
                $x = 0;
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
                break;
            case 'center':
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
                break;
            case 'right':
                $x = $size->getWidth() - $watermarkSize->getWidth();
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
                break;
            case 'bottomleft':
                $x = 0;
                $y = $size->getHeight() - $watermarkSize->getHeight();
                break;
            case 'bottom':
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
                $y = $size->getHeight() - $watermarkSize->getHeight();
                break;
            case 'bottomright':
                $x = $size->getWidth() - $watermarkSize->getWidth();
                $y = $size->getHeight() - $watermarkSize->getHeight();
                break;
            default:
                throw new \InvalidArgumentException("Unexpected position '{$options['position']}'");
                break;
        }

        return $image->paste($watermark, new Point($x, $y));
    }
833517
private function isInsideImage(ImageInterface $image, $x, $y, $width, $height)
    {
        if ($x < 0 || $y < 0) {
            return false;
        }
        if ($x + $width > $image->getSize()->getWidth()) {
            return false;
        }
        if ($y + $height > $image->getSize()->getHeight()) {
            return false;
        }

        return true;
    }
354362
public function applyFilter(Image $image)
    {
        if ($image->width() >= $image->height())
        {
            return $image->resize(272, null, function ($constraint)
            {
                $constraint->aspectRatio();
            });
        }

        return $image->resize(null, 272, function ($constraint)
        {
            $constraint->aspectRatio();
        });
    }