/** * @param $path * @param bool $png24 * @return $this */ public function mask($path, $png24 = false) { $this->checkFinalized(); $command = new Command(__TRAIT__, function () { return ' -compose Dst_In -composite'; }); $this->addFinalizeListener(function (CommandBuilder $builder) use($command) { if (false !== ($save = $builder->getFirstCommand(Save::class))) { $command->setPriority($save->getPriority() - 1); } }); $this->image($path, $png24); $this->addCommand($command); return $this; }
/** * @param null $width * @param null $height * @return $this */ public function resize($width = null, $height = null) { $this->checkFinalized(); if (null === $width && null === $height) { return $this; } $command = new Command(__TRAIT__, function (Command $command) { return ($command->addDensity ? ' -density ' . $command->width : '') . ' -resize ' . (0 == $command->width ? '' : $command->width) . 'x' . (0 == $command->height ? '' : $command->height); }); $command->addDensity = false; $command->width = (int) round($width); $command->height = (int) round($height); $this->addFinalizeListener(function (CommandBuilder $builder) use($command) { if (false !== ($open = $builder->getFirstCommand(Open::class)) && 'svg' == strtolower(pathinfo($open->path, PATHINFO_EXTENSION))) { $command->addDensity = true; $command->setPriority($open->getPriority() - 1); } }); $this->addCommand($command); return $this; }
/** * @param null $width * @param null $height * @return $this */ public function extent($width = null, $height = null) { $this->checkFinalized(); $command = new Command(__TRAIT__, function (Command $command) { return ' -extent ' . (0 == $command->width ? '' : $command->width) . 'x' . (0 == $command->height ? '' : $command->height); }); $command->width = (int) round($width); $command->height = (int) round($height); $this->addFinalizeListener(function (CommandBuilder $builder) use($command) { if (!$builder->getFirstCommand(Background::class)) { $builder->background(); $builder->getLastCommand()->setPriority($command->getPriority() - 1); } if (false !== ($halign = $builder->getFirstCommand(HAlign::class))) { $halign->setPriority($command->getPriority() - 1); } if (false !== ($valign = $builder->getFirstCommand(VAlign::class))) { $valign->setPriority($command->getPriority() - 1); } }); $this->addCommand($command); return $this; }