diff --git a/.gitignore b/.gitignore index 830f4d6f..15d3bc4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store composer.lock vendor/ -dev/ \ No newline at end of file +dev/ +.idea \ No newline at end of file diff --git a/composer.json b/composer.json index b8114a15..45a57dba 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ }, "require-dev": { "phpunit/phpunit": "3.*", - "mockery/mockery": "~0.9.2" + "mockery/mockery": "~0.9.2", + "guzzlehttp/psr7": "~1.1" }, "suggest": { "ext-gd": "to use GD library based image processing.", diff --git a/src/Intervention/Image/Commands/PsrResponseCommand.php b/src/Intervention/Image/Commands/PsrResponseCommand.php new file mode 100644 index 00000000..5624a113 --- /dev/null +++ b/src/Intervention/Image/Commands/PsrResponseCommand.php @@ -0,0 +1,45 @@ +argument(0)->value(); + $quality = $this->argument(1)->between(0, 100)->value(); + + //Encoded property will be populated at this moment + $stream = $image->stream($format, $quality); + + $mimetype = finfo_buffer( + finfo_open(FILEINFO_MIME_TYPE), + $image->encoded + ); + + $this->setOutput(new Response( + 200, + array( + 'Content-Type' => $mimetype, + 'Content-Length' => strlen($image->encoded) + ), + $stream + )); + + return true; + } +} \ No newline at end of file diff --git a/src/Intervention/Image/Commands/StreamCommand.php b/src/Intervention/Image/Commands/StreamCommand.php new file mode 100644 index 00000000..39fc698c --- /dev/null +++ b/src/Intervention/Image/Commands/StreamCommand.php @@ -0,0 +1,25 @@ +argument(0)->value(); + $quality = $this->argument(1)->between(0, 100)->value(); + + $this->setOutput(\GuzzleHttp\Psr7\stream_for( + $image->encode($format, $quality)->encoded + )); + + return true; + } +} \ No newline at end of file diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 382ab288..8dff8a1b 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -2,6 +2,9 @@ namespace Intervention\Image; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; + /** * @method \Intervention\Image\Image backup(string $name = 'default') Backups current image state as fallback for reset method under an optional name. Overwrites older state on every call, unless a different name is passed. * @method \Intervention\Image\Image blur(integer $amount = 1) Apply a gaussian blur filter with a optional amount on the current image. Use values between 0 and 100. @@ -45,6 +48,8 @@ namespace Intervention\Image; * @method \Intervention\Image\Image text(string $text, integer $x = 0, integer $y = 0, \Closure $callback = null) Write a text string to the current image at an optional x,y basepoint position. You can define more details like font-size, font-file and alignment via a callback as the fourth parameter. * @method \Intervention\Image\Image trim(string $base = 'top-left', array $away = array('top', 'bottom', 'left', 'right'), integer $tolerance = 0, integer $feather = 0) Trim away image space in given color. Define an optional base to pick a color at a certain position and borders that should be trimmed away. You can also set an optional tolerance level, to trim similar colors and add a feathering border around the trimed image. * @method \Intervention\Image\Image widen(integer $width, \Closure $callback = null) Resizes the current image to new width, constraining aspect ratio. Pass an optional Closure callback as third parameter, to apply additional constraints like preventing possible upsizing. + * @method StreamInterface stream(string $format = null, integer $quality = 90) Builds PSR-7 compatible StreamInterface with current image in given format and quality. + * @method ResponseInterface psrResponse(string $format = null, integer $quality = 90) Builds PSR-7 compatible ResponseInterface with current image in given format and quality. */ class Image extends File {