Limit image size to maximum allowed image size.
@param  integer   $width  The image width.
@param  integer   $height The image height.
@return integer[] The limited width and height.
3623
public function limitImageSize($width, $height)
    {
        if ($this->maxImageSize !== null) {
            $imageSize = $width * $height;

            if ($imageSize > $this->maxImageSize) {
                $width = $width / sqrt($imageSize / $this->maxImageSize);
                $height = $height / sqrt($imageSize / $this->maxImageSize);
            }
        }

        return [
            (int) $width,
            (int) $height,
        ];
    }
1152433
public function fit($width, $height)
    {
        $this->toggleModified();

        $this->getInterventionImage()->fit($width, $height);

        return $this;
    }
825678
public function fit($width, $height)
    {
        $this->mode = 'resizeToFit';
        $this->targetSize = [$width, $height];
        $this->arguments = [];

        return $this->process();
    }
1072018
public function resize($width, $height) {

        $new = @imagecreatetruecolor($width, $height);

        // This needed to deal with .png transparency
        imagealphablending($new, false);
        imagesavealpha($new, true);
        $transparent = imagecolorallocatealpha($new, 255, 255, 255, 127);
        imagefilledrectangle($new, 0, 0, $width, $height, $transparent);

        imagecopyresampled($new, $this->resource, 0, 0, 0, 0, $width, $height,
            $this->width(), $this->height());
        $this->resource = $new;

        // for method chaining
        return $this;
    }
1282342
public function runContainResize(Image $image, $width, $height)
    {
        return $image->resize($width, $height, function ($constraint) {
            $constraint->aspectRatio();
        });
    }
1092219
private function getImageWidth(Image $image, int $height): int
    {
        return (int)($height * ($image->getWidth() / $image->getHeight()));
    }
1216151
public function resize($width, $height)
    {
        $width = (int)$width;
        $height = (int)$height;
        $tmpImage = imagecreatetruecolor($width, $height);
        imagefilledrectangle($tmpImage, 0, 0, $width, $height, $this->backgroundColor);
        imagecopyresampled($tmpImage, $this->resource, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
        $this->width = $width;
        $this->height = $height;
        $this->resource = $tmpImage;
    }
235489
public function resizeOut($width, $height)
        {
            if (false === $this->_options['resizeUp']) {
                $this->_maxHeight = (intval($height) > $this->_sourceHeight) ? $this->_sourceHeight:$height;
                $this->_maxWidth = (intval($width) > $this->_sourceWidth) ? $this->_sourceWidth:$width;
            } else {
                $this->_maxHeight = intval($height);
                $this->_maxWidth = intval($width);
            }

            list($newWidth, $newHeight) = $this->_calcImageSizeStrict($this->_sourceWidth, $this->_sourceHeight);

            // resize the image to be close to our desired dimensions
            $this->resizeIn($newWidth, $newHeight);

            return $this;
        }
415242
private function getAdjustedImageDimensions(Image $image, int $width, int $height, bool $crop = false): array
    {
        if ($image->getWidth() / $image->getHeight() > $width / $height) {		// current is wider than new
            if (true === $crop) {	// upscale prevention
                return [
                    'width' => $this->getImageWidth($image, $height),
                    'height' => $height,
                ];
            } else {
                return [
                    'width' => $width,
                    'height' => $this->getImageHeight($image, $width),
                ];
            }
        } elseif ($image->getWidth() / $image->getHeight() < $width / $height) {	// current is taller than new
            if (true === $crop) {	// upscale prevention
                return [
                    'width' => $width,
                    'height' => $this->getImageHeight($image, $width),
                ];
            } else {
                return [
                    'width' => $this->getImageWidth($image, $height),
                    'height' => $height,
                ];
            }
        } else {									// current has same aspect ratio as new
            return [
                'width' => $width,
                'height' => $height,
            ];
        }
    }
997990
public function getNewDimensions($width, $height)
    {
        if(!$this->resizeSmaller && $this->height >= $height && $this->width >= $width)
        {
            return parent::getNewDimensions($width, $height);
        }

        if(in_array($this->resizeMode, array($this::MODE_CROP, $this::MODE_STRETCH, $this::MODE_EXACT)))
        {
            return parent::getNewDimensions($this->width, $this->height);
        }
        elseif($this->resizeMode === $this::MODE_FILL)
        {
            $ratioH = $this->height / $height;
            $ratioW = $this->width / $width;

            $widthFill  = max($width * $ratioH, $width * $ratioW);
            $heightFill = max($height * $ratioH, $height * $ratioW);
            $ratio = max($widthFill / $width, $heightFill / $height);

            return parent::getNewDimensions(round($width * $ratio), round($height * $ratio));
        }
        else
        {
            $pictureWidth  = $this->width;
            $pictureHeight = $this->height;

            if($width > $pictureWidth || $height > $pictureHeight)
            {
                if($width > $height)
                {
                    $pictureHeight = floor(($height / $width) * $pictureWidth);
                }
                elseif($width < $height)
                {
                    $pictureWidth = floor(($width / $height) * $pictureHeight);
                }
            }

            return parent::getNewDimensions($pictureWidth, $pictureHeight);
        }
    }
973922
public function resize($width, $height)
    {

        $new = imagecreatetruecolor($width, $height);
        imagealphablending($new, false);
        imagesavealpha($new, true);
        imagecopyresampled($new, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);

        $this->width = $width;
        $this->height = $height;
        $this->image = $new;

        return $this;

    }
429936
public function croppedImages($width = null, $height = null, $options = null)
    {
        return array_combine(

            // Keys
            $this->images->map(function ($image) {
                return $image->name ?: 'default';
            })->toArray(),

            // Values
            $this->images->map(function ($image) use ($width, $height, $options) {
                return $image->crop($width, $height, $options)->url;
            })->toArray()
        );
    }
1002348
protected function calcImageSize($width, $height)
    {
        $newSize = array(
            'newWidth' => $width,
            'newHeight' => $height
        );

        if ($this->maxWidth > 0) {
            $newSize = $this->calcWidth($width, $height);

            if ($this->maxHeight > 0 && $newSize['newHeight'] > $this->maxHeight) {
                $newSize = $this->calcHeight($newSize['newWidth'], $newSize['newHeight']);
            }
        }

        if ($this->maxHeight > 0) {
            $newSize = $this->calcHeight($width, $height);

            if ($this->maxWidth > 0 && $newSize['newWidth'] > $this->maxWidth) {
                $newSize = $this->calcWidth($newSize['newWidth'], $newSize['newHeight']);
            }
        }

        $this->newDimensions = $newSize;
    }
314065
public function scaleResize($width, $height) {

        // calculate source coordinates
        $kw = $this->width() / $width;
        $kh = $this->height() / $height;
        if($kh < $kw) {
            $src_h = $this->height();
            $src_y = 0;
            $src_w = round($kh * $width);
            $src_x = round(($this->width() - $src_w) / 2);
        } else {
            $src_h = round($kh * $height);
            $src_y = round(($this->height() - $src_h) / 2);
            $src_w = $this->width();
            $src_x = 0;
        }

        // copy new image
        $new = imagecreatetruecolor($width, $height);
        imagecopyresampled($new, $this->resource, 0, 0, $src_x, $src_y,
            $width, $height, $src_w, $src_h);
        $this->resource = $new;

        // for method chaining
        return $this;
    }
167735
public function resize(Image $image, $width, $height, $method)
    {
        // Get Image Dimensions:
        
        $imageWidth  = $image->getWidth();
        $imageHeight = $image->getHeight();
        
        // Calculate Width and Height (if required):
        
        if ($width && !$height && $imageWidth) {
            $height = round(($width / $imageWidth) * $imageHeight);
        } elseif (!$width && $height && $imageHeight) {
            $width = round(($height / $imageHeight) * $imageWidth);
        }
        
        // Perform Image Resizing:
        
        if ($width && $height) {
            
            switch (strtolower($method)) {
                
                case self::RESIZE_CROP_WIDTH:
                    return $image->CropWidth($width);
                    
                case self::RESIZE_CROP_HEIGHT:
                    return $image->CropHeight($height);
                    
                case self::RESIZE_FILL:
                    return $image->Fill($width, $height);
                    
                case self::RESIZE_FILL_MAX:
                    return $image->FillMax($width, $height);
                    
                case self::RESIZE_FILL_PRIORITY:
                    return $image->FillPriority($width, $height);
                    
                case self::RESIZE_FIT:
                    return $image->Fit($width, $height);
                    
                case self::RESIZE_FIT_MAX:
                    return $image->FitMax($width, $height);
                    
                case self::RESIZE_PAD:
                    return $image->Pad($width, $height);
                    
                case self::RESIZE_SCALE_WIDTH:
                    return $image->ScaleWidth($width);
                    
                case self::RESIZE_SCALE_HEIGHT:
                    return $image->ScaleHeight($height);
                    
                case self::RESIZE_SCALE_MAX_WIDTH:
                    return $image->ScaleMaxWidth($width);
                    
                case self::RESIZE_SCALE_MAX_HEIGHT:
                    return $image->ScaleMaxHeight($height);
                    
            }
            
        }
        
        // Answer Original Image:
        
        return $image;
    }
794065
public function listImagesWithDimension(int $width, int $height, array $sortOrder = null, array $limit = null) {
		$timeStamp = microtime(true);

        $filter[] = array(
            'glue' => ' and',
            'condition' => array(
                0 => array(
                    'glue' => ' and',
                    'condition' => array(
                        'column' => $this->entity['f']['alias'] . '.width',
                        'comparison' => '=',
                        'value' => $width
                    )),
                1 => array(
                    'glue' => ' and',
                    'condition' => array(
                        'column' => $this->entity['f']['alias'] . '.height',
                        'comparison' => '=',
                        'value' => $height
                    )))
        );
        $response =  $this->listFiles($filter, $sortOrder, $limit);
		$response->stats->execution->start = $timeStamp;
		$response->stats->execution->end = microtime(true);

		return $response;
    }
914723
public function runFillResize($image, $width, $height)
    {
        $image = $this->runMaxResize($image, $width, $height);

        return $image->resizeCanvas($width, $height, 'center');
    }