Creates image dimensions based on a configuration
@param  string $url
@param  array  $dimensions
@return void
775851
public function createDimensions($url, $dimensions = array())
    {
        // Get default dimensions
        $defaultDimensions = Config::get('redminportal::image.dimensions');
     
        if (is_array($defaultDimensions)) {
            $dimensions = array_merge($defaultDimensions, $dimensions);
        }
     
        foreach ($dimensions as $dimension) {
            // Get dimmensions and quality
            $width   = (int) $dimension[0];
            $height  = isset($dimension[1]) ?  (int) $dimension[1] : $width;
            $crop    = isset($dimension[2]) ? (bool) $dimension[2] : false;
            $quality = isset($dimension[3]) ?  (int) $dimension[3] : Config::get('redminportal::image.quality');
     
            // Run resizer
            $this->resize($url, $width, $height, $crop, $quality);
        }
    }
1209930
public function resize($url, $width = 100, $height = null, $crop = false, $quality = 90)
    {
        if ($url) {
            // URL info
            $info = pathinfo($url);
     
            // The size
            if (! $height) {
                $height = $width;
            }
     
            // Quality
            $quality = Config::get('redminportal::image.quality', $quality);
     
            // Directories and file names
            $fileName       = $info['basename'];
            $sourceDirPath  = public_path() . '/' . $info['dirname'];
            $sourceFilePath = $sourceDirPath . '/' . $fileName;
            $targetDirName  = $width . 'x' . $height . ($crop ? '_crop' : '');
            $targetDirPath  = $sourceDirPath . '/' . $targetDirName . '/';
            $targetFilePath = $targetDirPath . $fileName;
            $targetUrl      = asset($info['dirname'] . '/' . $targetDirName . '/' . $fileName);
     
            // Create directory if missing
            try {
                // Create dir if missing
                if (! Filesystem::isDirectory($targetDirPath) and $targetDirPath) {
                    @Filesystem::makeDirectory($targetDirPath);
                }
     
                // Set the size
                $size = new Box($width, $height);
     
                // Now the mode
                $mode = $crop ? ImageInterface::THUMBNAIL_OUTBOUND : ImageInterface::THUMBNAIL_INSET;
     
                if (! Filesystem::exists($targetFilePath) or
                    (Filesystem::lastModified($targetFilePath) < Filesystem::lastModified($sourceFilePath))) {
                    $this->imagine->open($sourceFilePath)
                        ->thumbnail($size, $mode)
                        ->save($targetFilePath, array('quality' => $quality));
                }
            } catch (\Exception $e) {
                Log::error('[IMAGE SERVICE] Failed to resize image "' . $url . '" [' . $e->getMessage() . ']');
            }
     
            return $targetUrl;
        }
    }
387118
public function resize($width, $height)
    {
        //if the width is not specified, make it relative to the height
        if($width == -1){

            $this->width['dest'] = ($height * $this->width['orig']) / $this->height['orig'];
            $this->height['dest'] = $height;

        //if the height is not specified, make it relative to the width
        } elseif ($height == -1){

            $this->width['dest'] = $width;
            $this->height['dest'] = ($width * $this->height['orig']) / $this->width['orig'];

        } else {

            $this->width['dest'] = $width;
            $this->height['dest'] = $height;
        }

        //set resize code depending on the type of image it is
        switch ($this->type)

    {
            case "gif":
                $this->edited = imagecreate($this->width['dest'], $this->height['dest']);

                imagecopyresampled($this->edited, $this->original, 0, 0, 0, 0, $this->width['dest'], $this->height['dest'], $this->width['orig'], $this->height['orig']);

            break;

            case "jpg":
                $this->edited = imagecreatetruecolor($this->width['dest'], $this->height['dest']);

                imagecopyresampled($this->edited, $this->original, 0, 0, 0, 0, $this->width['dest'], $this->height['dest'], $this->width['orig'], $this->height['orig']);


            break;

            case "png":

                $this->edited = imagecreatetruecolor ($this->width['dest'], $this->height['dest']);

                //preserve the alpha if exists
                imagealphablending($this->edited, false);
                imagesavealpha($this->edited, true);

                imagecopyresampled($this->edited, $this->original, 0, 0, 0, 0, $this->width['dest'], $this->height['dest'], $this->width['orig'], $this->height['orig']);

            break;
        }

    }
396956
private function init(string $url): void
    {
        $this->resource = curl_init($url);

        curl_setopt($this->resource, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->resource, CURLOPT_CONNECTTIMEOUT, $this->loader->getTimeout());
        curl_setopt($this->resource, CURLOPT_USERAGENT, $this->loader->getUserAgent());
        curl_setopt($this->resource, CURLOPT_HEADER, true);
        curl_setopt($this->resource, CURLINFO_HEADER_OUT, true);

        // check and set proxy settings
        $proxy_host = $this->loader->getOption('ProxyHost');

        if (null !== $proxy_host) {
            // check for supported protocol
            $proxy_protocol = $this->loader->getOption('ProxyProtocol');

            if (null !== $proxy_protocol) {
                $allowedProtocolls = [StreamCreator::PROXY_PROTOCOL_HTTP, StreamCreator::PROXY_PROTOCOL_HTTPS];

                if (!in_array($proxy_protocol, $allowedProtocolls)) {
                    throw new Exception(
                        'Invalid/unsupported value "' . $proxy_protocol . '" for option "ProxyProtocol".',
                        Exception::INVALID_OPTION
                    );
                }
            } else {
                $proxy_protocol = StreamCreator::PROXY_PROTOCOL_HTTP;
            }

            $proxy_port = $this->loader->getOption('ProxyPort');

            // set basic proxy options
            curl_setopt($this->resource, CURLOPT_PROXY, $proxy_protocol . '://' . $proxy_host);
            if (null !== $proxy_port) {
                curl_setopt($this->resource, CURLOPT_PROXYPORT, $proxy_port);
            }

            // check auth settings
            $proxy_user = $this->loader->getOption('ProxyUser');

            // set proxy auth options
            if (null !== $proxy_user) {
                $proxy_password = $this->loader->getOption('ProxyPassword');

                $proxy_auth = $this->loader->getOption('ProxyAuth');
                if (null !== $proxy_auth) {
                    $allowedAuth = [StreamCreator::PROXY_AUTH_BASIC, StreamCreator::PROXY_AUTH_NTLM];

                    if (!in_array($proxy_auth, $allowedAuth)) {
                        throw new Exception(
                            'Invalid/unsupported value "' . $proxy_auth . '" for option "ProxyAuth".',
                            Exception::INVALID_OPTION
                        );
                    }
                } else {
                    $proxy_auth = StreamCreator::PROXY_AUTH_BASIC;
                }

                if (StreamCreator::PROXY_AUTH_NTLM === $proxy_auth) {
                    curl_setopt($this->resource, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
                }
                curl_setopt($this->resource, CURLOPT_PROXYUSERPWD, $proxy_user . ':' . $proxy_password);
            }
        }
    }
498430
public function setSize(Dimension $dimension)
    {
        return $this->setWidth($dimension->getWidth())
                        ->setHeight($dimension->getHeight());
    }
1276629
protected function setRequestDimensions($request, array $handler)
    {
        if (!empty($handler['query']['dimensions'])) {

            $dimensions = array();

            foreach ((array) $handler['query']['dimensions'] as $name) {
                $dimension = new \Google_Service_AnalyticsReporting_Dimension;
                $dimension->setName($name);
                $dimensions[] = $dimension;
            }

            $request->setDimensions($dimensions);
        }
    }
783134
async function loadImageSize(url, cache) {
  let cacheKey = 'image#' + url;
  let ttl = 24 * 60 * 60 * 1000; // 1 day

  // Try get image dimensions from cache
  const cached = await cache.get(cacheKey);
  // If image dimensions in cache and not expired - return it
  if (cached && cached.ts > Date.now() - ttl) return cached.dimensions;

  // If no data in cache - fetch

  let dimensions;

  try {
    dimensions = await size(url);
  } catch (err) {
    // Suppress errors for broken data, return `null` instead
    if (err.code === 'ECONTENT') return null;
    throw err;
  }

  // Save data to cache
  await cache.set(cacheKey, { dimensions: dimensions, ts: Date.now() });

  return dimensions;
}
34335
public function addUrl(Url $url)
    {
        if ($this->isFull()) {
            throw new \RuntimeException('The urlset limit has been exceeded');
        }

        $urlXml = $url->toXml();
        $this->appendXML($urlXml);

        //add unknown custom namespaces
        $this->customNamespaces = array_merge($this->customNamespaces, $url->getCustomNamespaces());

        //---------------------
        //Check limits
        if ($this->countItems++ >= self::LIMIT_ITEMS) {
            $this->limitItemsReached = true;
        }

        $urlLength = strlen($urlXml);
        $this->countBytes += $urlLength;

        if ($this->countBytes + $urlLength + strlen($this->getStructureXml()) > self::LIMIT_BYTES) {
            //we suppose the next url is almost the same length and cannot be added
            //plus we keep 500kB (@see self::LIMIT_BYTES)
            //... beware of numerous images set in url
            $this->limitBytesReached = true;
        }
        //---------------------
    }
1073891
public static function getImageFromArray($data, $size, $dimensions = false)
    {
        if($dimensions === true)
        {
            $image = (object) [
                'url' => $data['sizes'][$size],
                'width' => $data['sizes'][$size . '-width'],
                'height' => $data['sizes'][$size . '-height']
            ];
        }
        else
        {
            $image = $data['sizes'][$size];
        }
        return $image;
    }
211227
public function setURL($url, $data = array())
    {
        $this->baseUrl = $url;
        $this->url = $this->buildURL($url, $data);
        $this->setOpt(CURLOPT_URL, $this->url);
    }
765490
public function process($url, $width = '', $height = '', $title = '', $options = [])
    {
        //If invalid URL passed, set to default image
        if (empty($url) || filter_var($url, FILTER_VALIDATE_URL) === false) {
            $url = $this->defaultImage;
        }

        $data = json_encode([
            'url' => $url,
            'width' => $width,
            'height' => $height,
            'default' => $this->defaultImage,
            'options' => array_merge($this->defaultOptions, $options)
        ]);

        $uri = base64_encode(json_encode([
            'data' => $data,
            'hash' => sha1($this->key.$this->secret.$data)
        ]));

        // Make the b64 string url-safe
        $uri = str_replace(['+', '/'], ['-', '_'], $uri);

        $fullUrl = [
            $this->host,
            $this->key,
            $uri,
            $this->filename($url, $title)
        ];

        return implode('/', $fullUrl);
    }
17042
public static function getResponsiveImageVars($dimensions, $imageFile)
    {
        $ret = array();
        $width = 0;
        $aspectRatio = 0;
        $ret['minWidth'] = 0;
        $ret['maxWidth'] = 0;
        if (isset($dimensions['width']) && $dimensions['width'] > 0) {
            $aspectRatio = $dimensions['height'] / $dimensions['width'] * 100;
            $width = $dimensions['width'];
            $ret['widthSteps'] = Kwf_Media_Image::getResponsiveWidthSteps($dimensions, $imageFile);
        }
        $ret['width'] = $width;
        $ret['aspectRatio'] = $aspectRatio;
        return $ret;
    }
1101509
public static function createIdentityMatrix($dimensions)
    {
        $grid = static::createFilledMatrix(null, $dimensions)->toArray();

        for ($x = 0; $x < $dimensions; ++$x) {
            $grid[$x][$x] = 1;
        }

        return new Matrix($grid);
    }
1330572
public function thumb($url, $width, $height = null)
    {
        return $this->resize($url, $width, $height, true);
    }
1153172
public function load($url)
    {
        if (file_exists($url)) {
            return $this->validate($url);
        }

        if (preg_match('#^(https?|spdy)://#', $url)) {

            if ($file = $this->loadRemoteFile($url)) {
                return $this->validate($file);
            }
        }

        throw new ImageResourceLoaderException(sprintf('Invalid Source URL: %s', $url));
    }
293090
public function updateURL(&$url)
    {
        // Skip if resampling is off, or is already resampled, or is not an image
        if (!Config::inst()->get(get_class($this), 'force_resample') || $this->getVariant() || !$this->getIsImage()) {
            return;
        }

        // Attempt to resample
        $resampled = $this->Resampled();
        if (!$resampled) {
            return;
        }

        // Only update if resampled file is a smaller file size
        if ($resampled->getAbsoluteSize() < $this->getAbsoluteSize()) {
            $url = $resampled->getURL();
        }
    }
862355
public static function create($url, string $mediaType = self::TYPE_IMAGE): self
    {
        return new self($url, $mediaType);
    }