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;
}
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()); }