Pimcore\Image\Adapter\Imagick::addOverlay PHP Method

addOverlay() public method

public addOverlay ( string $image, integer $x, integer $y, integer $alpha = 100, $composite = "COMPOSITE_DEFAULT", string $origin = 'top-left' ) : self
$image string
$x integer Amount of horizontal pixels the overlay should be offset from the origin
$y integer Amount of vertical pixels the overlay should be offset from the origin
$alpha integer Opacity in a scale of 0 (transparent) to 100 (opaque)
$origin string Origin of the X and Y coordinates (top-left, top-right, bottom-left, bottom-right or center)
return self
    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;
    }