Pop\Image\Gd::cropThumb PHP Метод

cropThumb() публичный Метод

Crop the image object to a square image
public cropThumb ( integer | string $px, integer | string $x, integer | string $y ) : Gd
$px integer | string
$x integer | string
$y integer | string
Результат Gd
    public function cropThumb($px, $x = 0, $y = 0)
    {
        // Determine whether or not the image is landscape or portrait and set
        // the scale, new width and new height accordingly, with the smallest
        // dimension being scaled to the value of the $px argument to allow
        // for a complete crop.
        $scale = $this->width > $this->height ? $px / $this->height : $px / $this->width;
        $wid = round($this->width * $scale);
        $hgt = round($this->height * $scale);
        // Create a new image output resource.
        $this->createResource();
        $this->output = imagecreatetruecolor($px, $px);
        // Copy newly sized image to the output resource.
        $this->copyImage($wid, $hgt, $x, $y);
        return $this;
    }

Usage Example

Пример #1
0
 public function testCropThumb()
 {
     $i = new Gd(__DIR__ . '/../tmp/test.jpg');
     $i->cropThumb(50);
     $this->assertEquals(50, $i->getWidth());
 }