Eventviva\ImageResize::freecrop PHP Méthode

freecrop() public méthode

Crops image according to the given width, height, x and y
public freecrop ( integer $width, integer $height, integer $x = false, integer $y = false ) : static
$width integer
$height integer
$x integer
$y integer
Résultat static
    public function freecrop($width, $height, $x = false, $y = false)
    {
        if ($x === false or $y === false) {
            return $this->crop($width, $height);
        }
        $this->source_x = $x;
        $this->source_y = $y;
        if ($width > $this->getSourceWidth() - $x) {
            $this->source_w = $this->getSourceWidth() - $x;
        } else {
            $this->source_w = $width;
        }
        if ($height > $this->getSourceHeight() - $y) {
            $this->source_h = $this->getSourceHeight() - $y;
        } else {
            $this->source_h = $height;
        }
        $this->dest_w = $width;
        $this->dest_h = $height;
        return $this;
    }

Usage Example

Exemple #1
0
 public function testFreeCrop()
 {
     $image = $this->createImage(200, 100, 'png');
     $resize = new ImageResize($image);
     $resize->freecrop(50, 50, $x = 20, $y = 20);
     $this->assertEquals(50, $resize->getDestWidth());
     $this->assertEquals(50, $resize->getDestHeight());
 }