Skip to content

Commit

Permalink
Backward compatibility for StreamCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jul 22, 2021
1 parent a5b24de commit e2b8aeb
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Intervention/Image/Commands/StreamCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit e2b8aeb

Please sign in to comment.