encode($this); } /** * Build new stream, run callback with it and return result as encoded image. * * @throws InvalidArgumentException * @throws StreamException */ protected function createEncodedImage(callable $callback, ?string $mediaType = null): EncodedImage { $stream = self::buildStreamOrFail(); $callback($stream); return is_string($mediaType) ? new EncodedImage($stream, $mediaType) : new EncodedImage($stream); } /** * {@inheritdoc} * * @see EncoderInterface::setOptions() * * @throws InvalidArgumentException */ public function setOptions(mixed ...$options): self { foreach ($options as $key => $value) { if (!property_exists($this, (string) $key)) { throw new InvalidArgumentException( 'Option $' . $key . ' does not exist on ' . $this::class, ); } $this->{$key} = $value; } return $this; } }