public function addOverlay($image, $x = 0, $y = 0, $alpha = 100, $composite = "COMPOSITE_DEFAULT", $origin = 'top-left')
{
$this->preModify();
// 100 alpha is default
if (empty($alpha)) {
$alpha = 100;
}
$alpha = round($alpha / 100, 1);
//Make sure the composite constant exists.
if (is_null(constant("Imagick::" . $composite))) {
$composite = "COMPOSITE_DEFAULT";
}
$newImage = null;
if (is_string($image)) {
$image = ltrim($image, "/");
$image = PIMCORE_DOCUMENT_ROOT . "/" . $image;
$newImage = new \Imagick();
$newImage->readimage($image);
} elseif ($image instanceof \Imagick) {
$newImage = $image;
}
if ($newImage) {
if ($origin == 'top-right') {
$x = $this->resource->getImageWidth() - $newImage->getImageWidth() - $x;
} elseif ($origin == 'bottom-left') {
$y = $this->resource->getImageHeight() - $newImage->getImageHeight() - $y;
} elseif ($origin == 'bottom-right') {
$x = $this->resource->getImageWidth() - $newImage->getImageWidth() - $x;
$y = $this->resource->getImageHeight() - $newImage->getImageHeight() - $y;
} elseif ($origin == 'center') {
$x = round($this->resource->getImageWidth() / 2) - round($newImage->getImageWidth() / 2) + $x;
$y = round($this->resource->getImageHeight() / 2) - round($newImage->getImageHeight() / 2) + $y;
}
$newImage->evaluateImage(\Imagick::EVALUATE_MULTIPLY, $alpha, \Imagick::CHANNEL_ALPHA);
$this->resource->compositeImage($newImage, constant("Imagick::" . $composite), $x, $y);
}
$this->postModify();
return $this;
}