From e2b8aebe3e5baf1e3db61a0f5227502313d74b29 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 22 Jul 2021 16:31:32 +0200 Subject: [PATCH] Backward compatibility for StreamCommand --- .../Image/Commands/StreamCommand.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Intervention/Image/Commands/StreamCommand.php b/src/Intervention/Image/Commands/StreamCommand.php index 6d659147..bc2ff9ef 100644 --- a/src/Intervention/Image/Commands/StreamCommand.php +++ b/src/Intervention/Image/Commands/StreamCommand.php @@ -15,11 +15,25 @@ class StreamCommand extends AbstractCommand { $format = $this->argument(0)->value(); $quality = $this->argument(1)->between(0, 100)->value(); + $data = $image->encode($format, $quality)->getEncoded(); - $this->setOutput(\GuzzleHttp\Psr7\Utils::streamFor( - $image->encode($format, $quality)->getEncoded() - )); + $this->setOutput($this->getStream($data)); return true; } + + /** + * Create stream from given data + * + * @param string $data + * @return \Psr\Http\Message\StreamInterface + */ + protected function getStream($data) + { + if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { + return \GuzzleHttp\Psr7\Utils::streamFor($data); // guzzlehttp/psr7 >= 2.0 + } + + return \GuzzleHttp\Psr7\stream_for($data); // guzzlehttp/psr7 < 2.0 + } }