public function cover($width, $height, $orientation = "center", $doNotScaleUp = true)
{
$scaleUp = $doNotScaleUp ? false : true;
$ratio = $this->getWidth() / $this->getHeight();
if ($width / $height > $ratio) {
$this->scaleByWidth($width, $scaleUp);
} else {
$this->scaleByHeight($height, $scaleUp);
}
if ($orientation == "center") {
$cropX = ($this->getWidth() - $width) / 2;
$cropY = ($this->getHeight() - $height) / 2;
} elseif ($orientation == "topleft") {
$cropX = 0;
$cropY = 0;
} elseif ($orientation == "topright") {
$cropX = $this->getWidth() - $width;
$cropY = 0;
} elseif ($orientation == "bottomleft") {
$cropX = 0;
$cropY = $this->getHeight() - $height;
} elseif ($orientation == "bottomright") {
$cropX = $this->getWidth() - $width;
$cropY = $this->getHeight() - $height;
} elseif ($orientation == "centerleft") {
$cropX = 0;
$cropY = ($this->getHeight() - $height) / 2;
} elseif ($orientation == "centerright") {
$cropX = $this->getWidth() - $width;
$cropY = ($this->getHeight() - $height) / 2;
} elseif ($orientation == "topcenter") {
$cropX = ($this->getWidth() - $width) / 2;
$cropY = 0;
} elseif ($orientation == "bottomcenter") {
$cropX = ($this->getWidth() - $width) / 2;
$cropY = $this->getHeight() - $height;
} else {
$cropX = null;
$cropY = null;
}
if ($cropX !== null && $cropY !== null) {
$this->crop($cropX, $cropY, $width, $height);
} else {
Logger::error("Cropping not processed, because X or Y is not defined or null, proceeding with next step");
}
return $this;
}