Pimcore\Image\Adapter\ImageMagick::setBackgroundImage PHP Метод

setBackgroundImage() публичный Метод

Set the image background
public setBackgroundImage ( $image, null $mode = null, $relativePath = false ) : ImageMagick
$image
$mode null
Результат ImageMagick
    public function setBackgroundImage($image, $mode = null, $relativePath = false)
    {
        $imagePath = $relativePath ? PIMCORE_DOCUMENT_ROOT . "/" . ltrim($image, "/") : $image;
        if (is_file($imagePath)) {
            //if a specified file as a background exists
            //creates the temp file for the background
            $newImage = $this->createTmpImage($imagePath, 'background');
            if ($mode == "cropTopLeft") {
                //crop the background image
                $newImage->crop(0, 0, $this->getWidth(), $this->getHeight());
            } else {
                // default behavior (fit)
                $newImage->resize($this->getWidth(), $this->getHeight());
            }
            $newImage->save($newImage->getOutputPath());
            //save current state of the thumbnail to the tmp file
            $this->saveIfRequired('gravity');
            //save the current state of the file (with a background)
            $this->compositeCommandOptions = [];
            $this->addCompositeOption('gravity', 'center ' . $this->getOutputPath() . ' ' . $newImage->getOutputPath() . ' ' . $this->getOutputPath());
            $this->processCommand($this->getCompositeCommand());
            $this->imagePath = $this->getOutputPath();
        }
        return $this;
    }