/** * Crops the image * * @param integer|string $width The new width of the image. It can be a number (pixels) or percentaje * @param integer|string $height The new height of the image. It can be a number (pixels) or percentaje * @param integer|string $x The "x" position to crop. It can be number (pixels), percentaje, [left, center, right] or one of the Image::CROP_* constants * @param integer|string $y The "y" position to crop. It can be number (pixels), percentaje or [top, middle, bottom] * * @return self */ public function crop($width, $height, $x = 'center', $y = 'middle') { $imageWidth = $this->getWidth(); $imageHeight = $this->getHeight(); $width = Dimmensions::getIntegerValue($width, $imageWidth); $height = Dimmensions::getIntegerValue($height, $imageHeight); switch ($x) { case Image::CROP_BALANCED: case Image::CROP_ENTROPY: list($x, $y) = $this->image->getCropOffsets($width, $height, $x); break; } $x = Dimmensions::getPositionValue($x, $width, $imageWidth); $y = Dimmensions::getPositionValue($y, $height, $imageHeight); $this->image->crop($width, $height, $x, $y); return $this; }
/** * @dataProvider integerValueDataProvider */ public function testIntegerValue($value, $relatedValue, $expected) { $result = Dimmensions::getIntegerValue($value, $relatedValue, true); $this->assertSame($expected, $result); }