newImage($width, $height, $background, 'png'); $imagick->setType(Imagick::IMGTYPE_UNDEFINED); $imagick->setImageType(Imagick::IMGTYPE_UNDEFINED); $imagick->setColorspace(Imagick::COLORSPACE_SRGB); $imagick->setImageResolution(96, 96); $imagick->setImageBackgroundColor($background); return new Image($this, new Core($imagick)); } /** * {@inheritdoc} * * @throws RuntimeException * @see DriverInterface::createAnimation() */ public function createAnimation(callable $init): ImageInterface { $imagick = new Imagick(); $imagick->setFormat('gif'); $animation = new class ($this, $imagick) { public function __construct( protected DriverInterface $driver, public Imagick $imagick ) { } /** * @throws RuntimeException */ public function add(mixed $source, float $delay = 1): self { $native = $this->driver->handleInput($source)->core()->native(); $native->setImageDelay(intval(round($delay * 100))); $this->imagick->addImage($native); return $this; } /** * @throws RuntimeException */ public function __invoke(): ImageInterface { return new Image( $this->driver, new Core($this->imagick) ); } }; $init($animation); return call_user_func($animation); } /** * {@inheritdoc} * * @see DriverInterface::colorProcessor() */ public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface { return new ColorProcessor($colorspace); } /** * {@inheritdoc} * * @see DriverInterface::fontProcessor() */ public function fontProcessor(): FontProcessorInterface { return new FontProcessor(); } /** * {@inheritdoc} * * @see DriverInterface::supports() */ public function supports(string|Format|FileExtension|MediaType $identifier): bool { try { $format = Format::create($identifier); } catch (NotSupportedException) { return false; } return count(Imagick::queryFormats($format->name)) >= 1; } }