Save the current image with max width and height keeping ratio

@param int    $width  max width of the image
@param int    $height max height of the image
@param string $path   File system path to save the image to
501652
public function saveMaxWidthHeight($width, $height = 20000, $path = 'i')
    {
        $this->handle->image_resize = true;
        $this->handle->image_ratio  = true;
        $this->handle->image_x      = $width;
        $this->handle->image_y      = $height;

        $tmp_path = sys_get_temp_dir() . '/';
        $this->handle->process($tmp_path);

        $this->s3->sendFile($tmp_path . $this->handle->file_dst_name, $path, $this->_new_name);
        unlink($tmp_path . $this->handle->file_dst_name);

        return $this->_new_name;
    }
1278581
public function dimension($width, $height = 0): self
    {
        if (empty($height)) {
            $height = $width;
        }

        return $this->set('dimension', compact('width', 'height'));
    }
278659
public function saveFixedWidth($width, $path = 'i')
    {
        $this->handle->image_resize  = true;
        $this->handle->image_ratio_y = true;
        $this->handle->image_x       = $width;

        $tmp_path = sys_get_temp_dir() . '/';
        $this->handle->process($tmp_path);

        $this->s3->sendFile($tmp_path . $this->handle->file_dst_name, $path, $this->_new_name);
        unlink($tmp_path . $this->handle->file_dst_name);

        return $this->_new_name;
    }
564521
public function resize($width, $height) {
        if (!$width) $width = 1;
        if (!$height) $height = 1;
        return (
            (false !== ($img = new gd(array($width, $height)))) &&
            $img->imagecopyresampled($this) &&
            (false !== ($this->image = $img->get_image())) &&
            (false !== ($this->width = $img->get_width())) &&
            (false !== ($this->height = $img->get_height()))
        );
    }
282232
public function set_window_size( $width, $height )
	{
		$width = $this->replace_variables( $width );
		$height = $this->replace_variables( $height );

		$this->getSession()->getDriver()->resizeWindow( $width, $height, 'current' );
	}
1305026
public function resize( $path, $name , $width = null , $height = null)
    {

        $img = \Image::make($path);

        // prevent possible upsizing
        $img->resize($width, $height, function ($constraint) {
            $constraint->aspectRatio();
            $constraint->upsize();
        });

        $img->save($path);
	}
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;
    }
772439
public function getThumbPath($path, $width, $height)
    {

        // 尺寸限制
        $allowSizeList = [0, 50, 100, 150, 200, 300, 400, 500, 640, 720, 800, 1000, 1200, 1680, 1920];
        $resetW = !in_array($width, $allowSizeList);
        $resetH = !in_array($height, $allowSizeList);

        if ($resetW || $resetH) {
            foreach ($allowSizeList as $size) {
                if ($resetW && $size > $width) {
                    $width = $size;
                    $resetW = false;
                }

                if ($resetH && $size > $height) {
                    $height = $size;
                    $resetH = false;
                }

                if (!$resetH && !$resetW) {
                    break;
                }
            }
        }

        $path = $this->getPathFromUrl($path);
        $path .= ".thumb.{$width}x{$height}.jpg";
        
        return $path;
    }
229588
public function do_resize($width, $height)
    {
        $this->_image->scaleImage($width, $height);

        $this->_width = $this->_image->getImageWidth();
        $this->_height = $this->_image->getImageHeight();

        return $this;
    }
487471
public function resizeImage($savePath, $image, $newImageName, $width, $height)
    {
        
        $fileImage = $image;
        $outputImg = null;
        $ext = pathinfo($newImageName, PATHINFO_EXTENSION);

        $thumb = imagecreatetruecolor($width, $height);
        list($w, $h) = getimagesize($fileImage);

        switch(exif_imagetype($fileImage)) {
            case IMAGETYPE_GIF:
                $image = imagecreatefromgif($fileImage);
            break;
            case IMAGETYPE_JPEG:
                $image = imagecreatefromjpeg($fileImage);
            break;
            case IMAGETYPE_PNG:
                $image = imagecreatefrompng($fileImage);
            break;
        }
        
        imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, $w, $h);

        switch ($ext) {
            case self::EXT_PNG:
                $outputImg = imagepng($thumb, $savePath.'/'.$newImageName, 9);
                break;
            case self::EXT_GIF:
                $outputImg = imagegif($thumb, $savePath.'/'.$newImageName);
                break;
            case self::EXT_JPG:
                $outputImg = imagejpeg($thumb, $savePath.'/'.$newImageName, 100);
                break;
        }

        imagedestroy($thumb);
    
    }
1094941
protected function thumbnailResize(Image $image, $width, $height)
    {
        return $image->resize($width, $height, function ($constraint) {
            $constraint->aspectRatio();
        });
    }
250187
protected function getNewWidth($width, $height) 
    {
        if ($width > 0) {
            return $width;
        }
        
        // original height : new height = original width : X
        return $height * $this->imageInfo['width'] / $this->imageInfo['height'];
    }
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;
    }
453548
private function updateImageInfo($width, $height) {
		$this->_image_info[0] = $width;
		$this->_image_info[1] = $height;
		$this->_image_info[3] = 'width="' . $width . '" height="' . $height . '"';
		$this->_image_info['aspect'] = $width / $height;
	}
1175371
public function create(int $width, int $height): self
    {
        $this->width = $width;
        $this->height = $height;
        $imageData = imagecreatetruecolor($this->width, $this->height);
        if (false === $imageData) {
            throw new ImageException('Unable to create new image!');
        }
        $this->workingData = $imageData;
        if (self::FORMAT_PNG === $this->extension) {
            $this->setTransparency(false, true);
        }
        if (self::FORMAT_GIF === $this->extension) {
            $this->setTransparency();
        }
        $this->encrypted = false;
        return $this;
    }
109796
public function limitToOuterBox($width, $height, $saveAsNewFile = false)
    {
        if ($this->getWidth() < $width && $this->getHeight() < $height) {
            return $saveAsNewFile ? $this : null;
        }
        return $this->scaleToOuterBox($width, $height, $saveAsNewFile);
    }
784593
public function setSize($width, $height)
    {
        $this->width = $width;
        $this->height = $height;
        $this->ratioX = $width / $height;
        $this->ratioY = $height / $width;

        return $this;
    }