wpfunnels
/
vendor
/
intervention
/
image
/
src
/
Intervention
/
Image
/
Commands
/
PsrResponseCommand.php
PsrResponseCommand.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/intervention/image/src/Intervention/Image/Commands/PsrResponseCommand.php
| 1 | <?php |
| 2 | |
| 3 | namespace Intervention\Image\Commands; |
| 4 | |
| 5 | use GuzzleHttp\Psr7\Response; |
| 6 | |
| 7 | class PsrResponseCommand extends AbstractCommand |
| 8 | { |
| 9 | /** |
| 10 | * Builds PSR7 compatible response. May replace "response" command in |
| 11 | * some future. |
| 12 | * |
| 13 | * Method will generate binary stream and put it inside PSR-7 |
| 14 | * ResponseInterface. Following code can be optimized using native php |
| 15 | * streams and more "clean" streaming, however drivers has to be updated |
| 16 | * first. |
| 17 | * |
| 18 | * @param \Intervention\Image\Image $image |
| 19 | * @return boolean |
| 20 | */ |
| 21 | public function execute($image) |
| 22 | { |
| 23 | $format = $this->argument(0)->value(); |
| 24 | $quality = $this->argument(1)->between(0, 100)->value(); |
| 25 | |
| 26 | //Encoded property will be populated at this moment |
| 27 | $stream = $image->stream($format, $quality); |
| 28 | |
| 29 | $mimetype = finfo_buffer( |
| 30 | finfo_open(FILEINFO_MIME_TYPE), |
| 31 | $image->getEncoded() |
| 32 | ); |
| 33 | |
| 34 | $this->setOutput(new Response( |
| 35 | 200, |
| 36 | [ |
| 37 | 'Content-Type' => $mimetype, |
| 38 | 'Content-Length' => strlen($image->getEncoded()) |
| 39 | ], |
| 40 | $stream |
| 41 | )); |
| 42 | |
| 43 | return true; |
| 44 | } |
| 45 | } |