mirror of
https://github.com/Intervention/image.git
synced 2025-07-31 11:00:12 +02:00
Response and stream commads added.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
.DS_Store
|
||||
composer.lock
|
||||
vendor/
|
||||
dev/
|
||||
dev/
|
||||
.idea
|
@@ -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.",
|
||||
|
45
src/Intervention/Image/Commands/PsrResponseCommand.php
Normal file
45
src/Intervention/Image/Commands/PsrResponseCommand.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Commands;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
class PsrResponseCommand extends AbstractCommand
|
||||
{
|
||||
/**
|
||||
* Builds PSR7 compatible response. May replace "response" command in
|
||||
* some future.
|
||||
*
|
||||
* Method will generate binary stream and put it inside PSR-7
|
||||
* ResponseInterface. Following code can be optimized using native php
|
||||
* streams and more "clean" streaming, however drivers has to be updated
|
||||
* first.
|
||||
*
|
||||
* @param \Intervention\Image\Image $image
|
||||
* @return boolean
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
$format = $this->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;
|
||||
}
|
||||
}
|
25
src/Intervention/Image/Commands/StreamCommand.php
Normal file
25
src/Intervention/Image/Commands/StreamCommand.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Commands;
|
||||
|
||||
class StreamCommand extends AbstractCommand
|
||||
{
|
||||
/**
|
||||
* Builds PSR7 stream based on image data. Method uses Guzzle PSR7
|
||||
* implementation as easiest choice.
|
||||
*
|
||||
* @param \Intervention\Image\Image $image
|
||||
* @return boolean
|
||||
*/
|
||||
public function execute($image)
|
||||
{
|
||||
$format = $this->argument(0)->value();
|
||||
$quality = $this->argument(1)->between(0, 100)->value();
|
||||
|
||||
$this->setOutput(\GuzzleHttp\Psr7\stream_for(
|
||||
$image->encode($format, $quality)->encoded
|
||||
));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user