GdThumb::cropFromCenter PHP Method

cropFromCenter() public method

If no height is given, the width will be used as a height, thus creating a square crop
public cropFromCenter ( integer $cropWidth, integer $cropHeight = null ) : GdThumb
$cropWidth integer
$cropHeight integer
return GdThumb
    public function cropFromCenter($cropWidth, $cropHeight = null)
    {
        if (!is_numeric($cropWidth)) {
            throw new InvalidArgumentException('$cropWidth must be numeric');
        }
        if ($cropHeight !== null && !is_numeric($cropHeight)) {
            throw new InvalidArgumentException('$cropHeight must be numeric');
        }
        if ($cropHeight === null) {
            $cropHeight = $cropWidth;
        }
        $cropWidth = $this->currentDimensions['width'] < $cropWidth ? $this->currentDimensions['width'] : $cropWidth;
        $cropHeight = $this->currentDimensions['height'] < $cropHeight ? $this->currentDimensions['height'] : $cropHeight;
        $cropX = intval(($this->currentDimensions['width'] - $cropWidth) / 2);
        $cropY = intval(($this->currentDimensions['height'] - $cropHeight) / 2);
        $this->crop($cropX, $cropY, $cropWidth, $cropHeight);
        return $this;
    }

Usage Example

Example #1
0
 public function zoom($width, $height = null)
 {
     return parent::cropFromCenter($width, $height);
 }
All Usage Examples Of GdThumb::cropFromCenter