From a5b24de3bf87186266061a0dedd2921da4152c09 Mon Sep 17 00:00:00 2001 From: Artem Davletshin <49448966+davlet42@users.noreply.github.com> Date: Sun, 18 Jul 2021 20:58:58 +0300 Subject: [PATCH 1/2] Update StreamCommand.php https://docs.guzzlephp.org/en/stable/psr7.html#streams --- src/Intervention/Image/Commands/StreamCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Intervention/Image/Commands/StreamCommand.php b/src/Intervention/Image/Commands/StreamCommand.php index 111c47569..6d659147d 100644 --- a/src/Intervention/Image/Commands/StreamCommand.php +++ b/src/Intervention/Image/Commands/StreamCommand.php @@ -16,10 +16,10 @@ public function execute($image) $format = $this->argument(0)->value(); $quality = $this->argument(1)->between(0, 100)->value(); - $this->setOutput(\GuzzleHttp\Psr7\stream_for( + $this->setOutput(\GuzzleHttp\Psr7\Utils::streamFor( $image->encode($format, $quality)->getEncoded() )); return true; } -} \ No newline at end of file +} From e2b8aebe3e5baf1e3db61a0f5227502313d74b29 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 22 Jul 2021 16:31:32 +0200 Subject: [PATCH 2/2] 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 6d659147d..bc2ff9efb 100644 --- a/src/Intervention/Image/Commands/StreamCommand.php +++ b/src/Intervention/Image/Commands/StreamCommand.php @@ -15,11 +15,25 @@ public function execute($image) { $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 + } }