encode($this); } /** * Build new file pointer, run callback with it and return result as encoded image * * @throws RuntimeException */ protected function createEncodedImage(callable $callback, ?string $mediaType = null): EncodedImage { $pointer = $this->buildFilePointer(); $callback($pointer); return is_string($mediaType) ? new EncodedImage($pointer, $mediaType) : new EncodedImage($pointer); } }