Skip to content

Commit

Permalink
Merge branch 'davlet42-patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jul 22, 2021
2 parents a2d7238 + e2b8aeb commit 0925f10
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 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\stream_for(
$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 0925f10

Please sign in to comment.