Sulu\Bundle\MediaBundle\Media\ImageConverter\Transformation\PasteTransformation::execute PHP Method

execute() public method

public execute ( Imagine\Image\ImageInterface $image, $parameters )
$image Imagine\Image\ImageInterface
    public function execute(ImageInterface $image, $parameters)
    {
        $maskPath = isset($parameters['image']) ? $this->fileLocator->locate($parameters['image']) : null;
        if (!$maskPath) {
            return $image;
        }
        $originalWidth = $image->getSize()->getWidth();
        $originalHeight = $image->getSize()->getHeight();
        $top = isset($parameters['top']) ? $parameters['top'] : 0;
        $left = isset($parameters['left']) ? $parameters['left'] : 0;
        $width = isset($parameters['width']) ? $parameters['width'] : $originalWidth;
        $height = isset($parameters['height']) ? $parameters['height'] : $originalHeight;
        // imagine will error when mask is bigger then the given image
        // this could happen in forceRatio true mode so we need also scale the mask
        if ($width > $originalWidth) {
            $width = $originalWidth;
            $height = (int) ($height / $width * $originalWidth);
        }
        if ($height > $originalHeight) {
            $height = $originalHeight;
            $width = (int) ($width / $height * $originalHeight);
        }
        // create mask
        $mask = $this->createMask($maskPath, $width, $height);
        // add mask to image
        $image->paste($mask, new Point($top, $left));
        return $image;
    }