Check image url.

@param  string  $image

@return string

@throws \Arcanedev\Gravatar\Exceptions\InvalidImageUrlException
160404
private function checkImageUrl($image)
    {
        if ( ! filter_var($image, FILTER_VALIDATE_URL)) {
            throw Exceptions\InvalidImageUrlException::make($image);
        }

        return $image;
    }
509314
public function apply( $image ) {

        imagefilter($image->getCore(), IMG_FILTER_PIXELATE, $this->amount, true);
        return $image;
    }
272202
public function execute($image)
    {
        if ($this->preferExtension && function_exists('exif_read_data')) {
            return parent::execute($image);
        }

        $core = $image->getCore();

        if ( ! method_exists($core, 'getImageProperties')) {
            throw new \Hail\Image\Exception\NotSupportedException(
                "Reading Exif data is not supported by this PHP installation."
            );
        }

        $requestedKey = $this->argument(0)->value();
        if ($requestedKey !== null) {
            $this->setOutput($core->getImageProperty('exif:' . $requestedKey));
            return true;
        }

        $exif = [];
        $properties = $core->getImageProperties();
        foreach ($properties as $key => $value) {
            if (substr($key, 0, 5) !== 'exif:') {
                continue;
            }

            $exif[substr($key, 5)] = $value;
        }

        $this->setOutput($exif);
        return true;
    }
1250402
private function getFile(Image $image)
    {
        $file = $image->getFile();

        if ($file instanceof \SplFileInfo) {
            return $file;
        }

        $url = $image->getUrl();

        if (null !== $url) {
            return new File($this->downloadFile($url));
        }

        return null;
    }
679381
public function execute($image)
    {
        $source = $this->argument(0)->required()->value();
        $position = $this->argument(1)->type('string')->value();
        $x = $this->argument(2)->type('digit')->value(0);
        $y = $this->argument(3)->type('digit')->value(0);

        // build watermark
        $watermark = $image->getDriver()->init($source);

        // define insertion point
        $image_size = $image->getSize()->align($position, $x, $y);
        $watermark_size = $watermark->getSize()->align($position);
        $target = $image_size->relativePosition($watermark_size);

        // insert image at position
        return $image->getCore()->compositeImage($watermark->getCore(), \Imagick::COMPOSITE_DEFAULT, $target->x, $target->y);
    }
1148408
private function initImage($image)
    {
        if(is_string($image))
        {
            return new Imagick($image);
        }
        elseif ($image instanceof Imagick)
        {
            return $image;
        }
        else
        {
            throw new Exception('Image input must be Imagick object or string path ('.gettype($image).' sent)');
        }
    }
535913
public function execute($image)
    {
        $filling = $this->argument(0)->value();
        $x = $this->argument(1)->type('digit')->value();
        $y = $this->argument(2)->type('digit')->value();

        $width = $image->getWidth();
        $height = $image->getHeight();
        $resource = $image->getCore();

        try {

            // set image tile filling
            $source = new Decoder;
            $tile = $source->init($filling);
            imagesettile($image->getCore(), $tile->getCore());
            $filling = IMG_COLOR_TILED;

        } catch (\Hail\Image\Exception\NotReadableException $e) {

            // set solid color filling
            $color = new Color($filling);
            $filling = $color->getInt();
        }

        imagealphablending($resource, true);

        if (is_int($x) && is_int($y)) {

            // resource should be visible through transparency
            $base = $image->getDriver()->newImage($width, $height)->getCore();
            imagecopy($base, $resource, 0, 0, 0, 0, $width, $height);

            // floodfill if exact position is defined
            imagefill($resource, $x, $y, $filling);

            // copy filled original over base
            imagecopy($base, $resource, 0, 0, 0, 0, $width, $height);

            // set base as new resource-core
            $image->setCore($base);
            imagedestroy($resource);

        } else {
            // fill whole image otherwise
            imagefilledrectangle($resource, 0, 0, $width - 1, $height - 1, $filling);
        }

        isset($tile) ? imagedestroy($tile->getCore()) : null;

        return true;
    }
1119811
private function getText($image)
    {
        $rtn = '';
        $w = imagesx($image);
        $h = imagesy($image);
        for ($y = 0; $y < $h; ++$y) {
            for ($x = 0; $x < $w; ++$x) {
                $rgb = imagecolorat($image, $x, $y);
                $rtn .= $this->getDotFromRgb($rgb);
            }
        }

        return $rtn;
    }
389969
private function init($image)
    {
        /** @var ConfigModel $settings */
        $settings = ImagerService::getConfig();

        if (\is_string($image)) {
            if (strncmp($image, $settings->imagerUrl, \strlen($settings->imagerUrl)) === 0) {
                // Url to a file that is in the imager library
                $this->getPathsForLocalImagerFile($image);
            } else {
                if (strncmp($image, '//', 2) === 0) {
                    // Protocol relative url, add https
                    $image = 'https:'.$image;
                }

                if (strncmp($image, 'http', 4) === 0 || strncmp($image, 'https', 5) === 0) {
                    // External url
                    $this->type = 'remoteurl';
                    $this->getPathsForUrl($image);
                } else {
                    // Relative path, assume that it's relative to document root
                    $this->getPathsForLocalFile($image);
                }
            }
        } else {
            // It's some kind of model
            if (\get_class($image) === 'aelvan\\imager\\models\\CraftTransformedImageModel') {
                $this->getPathsForLocalImagerFile($image->url);
            } else {
                if ($image instanceof Asset) {
                    $this->asset = $image;

                    // todo : Improve this check to take into account other volumes that are local?
                    try {
                        $volumeClass = \get_class($image->getVolume());
                    } catch (InvalidConfigException $e) {
                        Craft::error($e->getMessage(), __METHOD__);
                        throw new ImagerException($e->getMessage(), $e->getCode(), $e);
                    }

                    if ($volumeClass === 'craft\volumes\Local') {
                        $this->getPathsForLocalAsset($image);
                    } else {
                        $this->type = 'volume';
                        $this->getPathsForVolumeAsset($image);
                    }
                } else {
                    throw new ImagerException(Craft::t('imager', 'An unknown image object was used.'));
                }
            }
        }
    }
1124947
private function getPathsForLocalFile($image)
    {
        $this->transformPath = ImagerHelpers::getTransformPathForPath($image);
        $pathParts = pathinfo($image);

        $this->path = FileHelper::normalizePath(Yii::getAlias('@webroot').'/'.$pathParts['dirname']);
        $this->url = $image;
        $this->filename = $pathParts['basename'];
        $this->basename = $pathParts['filename'];
        $this->extension = $pathParts['extension'];
    }
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;
    }
784462
public function execute($image)
    {
        $color = $this->argument(0)->required()->value();
        $color = new Color($color);
        $x = $this->argument(1)->type('digit')->required()->value();
        $y = $this->argument(2)->type('digit')->required()->value();

        // prepare pixel
        $draw = new \ImagickDraw;
        $draw->setFillColor($color->getPixel());
        $draw->point($x, $y);

        // apply pixel
        return $image->getCore()->drawImage($draw);
    }
445276
private function getHashFilePath(AbstractLocalImage $image)
    {
        $path = $image->getRealpath();
        if (false !== $path) {
            return $path.self::$fileExtension;
        }
        // put it in the system tmp dir, if file doesn't have a real path.
        $identifier = $image->getIdentifier();
        if (null === $identifier) {
            $identifier = 'unknown_identifier';
        }

        return sys_get_temp_dir().'/'.str_replace('/', '__', $identifier).self::$fileExtension;
    }
553058
public function plate($image, bool $isUrl = false)
    {
        return $this->image(self::PLATE, $image, $isUrl);
    }
470203
public function fill($image) {
        $fill = $this->getConfig('fill');
        $r = $fill[0];
        $g = $fill[1];
        $b = $fill[2];
        $a = isset($fill[3]) ? $fill[3] : 127;

        imagefill($image, 0, 0, imagecolorallocatealpha($image, $r, $g, $b, $a));

        return $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'];
    }
308027
protected function makeGD($image)
  {
    if (is_resource($image)) {
      return $image;
    }

    if (!is_file($image)) {
      Ex::ThrowError(Ex::FILE_NOT_EXIST, $image);
    }

    $this->type = $this->getTypeByFile($image);

    switch ($this->type) {
      case IMG_JPEG:
        return imagecreatefromjpeg($image);
        break;
      case IMG_GIF:
        return imagecreatefromgif($image);
        break;
      case IMG_PNG:
        return imagecreatefrompng($image);
        break;
      default:
        $file = file_get_contents($image);

        return imagecreatefromstring($file);
    }
  }