Pop\Image\Gd::resize PHP Method

resize() public method

Resize the image object to the largest dimension
public resize ( integer | string $px ) : Gd
$px integer | string
return Gd
    public function resize($px)
    {
        // Determine whether or not the image is landscape or portrait and set
        // the scale, new width and new height accordingly, with the largest
        // dimension being scaled to the value of the $px argument.
        $scale = $this->width > $this->height ? $px / $this->width : $px / $this->height;
        $wid = round($this->width * $scale);
        $hgt = round($this->height * $scale);
        // Create a new image output resource.
        $this->createResource();
        $this->output = imagecreatetruecolor($wid, $hgt);
        // Copy newly sized image to the output resource.
        $this->copyImage($wid, $hgt);
        return $this;
    }

Usage Example

示例#1
0
 public function testResize()
 {
     $i = new Gd(__DIR__ . '/../tmp/test.jpg');
     $i->resize(240);
     $this->assertEquals(240, $i->getWidth());
 }