PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 3.2.4
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v3.2.4
4.1.2 4.1.1 4.1.0 4.0.1 4.0.0 3.3.1 3.3.0 trunk 1.0.0 2.0.0 2.1.0 3.0.0 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8
quickwebp / includes / vendor / intervention / image / src / Intervention / Image / Commands / StreamCommand.php

StreamCommand.php in QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress 3.2.4, at includes/vendor/intervention/image/src/Intervention/Image/Commands/StreamCommand.php

40 lines 1023 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Intervention\Image\Commands;
4
5 class StreamCommand extends AbstractCommand
6 {
7 /**
8 * Builds PSR7 stream based on image data. Method uses Guzzle PSR7
9 * implementation as easiest choice.
10 *
11 * @param \Intervention\Image\Image $image
12 * @return boolean
13 */
14 public function execute($image)
15 {
16 $format = $this->argument(0)->value();
17 $quality = $this->argument(1)->between(0, 100)->value();
18 $data = $image->encode($format, $quality)->getEncoded();
19
20 $this->setOutput($this->getStream($data));
21
22 return true;
23 }
24
25 /**
26 * Create stream from given data
27 *
28 * @param string $data
29 * @return \Psr\Http\Message\StreamInterface
30 */
31 protected function getStream($data)
32 {
33 if (class_exists(\GuzzleHttp\Psr7\Utils::class)) {
34 return \GuzzleHttp\Psr7\Utils::streamFor($data); // guzzlehttp/psr7 >= 2.0
35 }
36
37 return \GuzzleHttp\Psr7\stream_for($data); // guzzlehttp/psr7 < 2.0
38 }
39 }
40