mirror of
https://github.com/Intervention/image.git
synced 2025-08-19 12:11:26 +02:00
added direct output method
This commit is contained in:
@@ -1831,6 +1831,45 @@ class Image
|
||||
$this->original['height'] = $this->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send direct output with proper header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
// Determine image type
|
||||
$type = '';
|
||||
|
||||
// set type
|
||||
switch ($this->type) {
|
||||
case IMAGETYPE_PNG:
|
||||
$type = 'png';
|
||||
break;
|
||||
|
||||
case IMAGETYPE_JPEG:
|
||||
$type = 'jpg';
|
||||
break;
|
||||
|
||||
case IMAGETYPE_GIF:
|
||||
$type = 'gif';
|
||||
break;
|
||||
}
|
||||
|
||||
// If this is a Laravel application, prepare response object
|
||||
if (function_exists('app') && is_a($app = app(), 'Illuminate\Foundation\Application'))
|
||||
{
|
||||
$response = \Response::make($this->encode());
|
||||
$response->header('Content-type', 'image/' . $type);
|
||||
return $response;
|
||||
}
|
||||
|
||||
// If this is not Laravel, set header directly
|
||||
header('Content-type: image/' . $type);
|
||||
|
||||
return $this->encode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns image stream
|
||||
*
|
||||
|
Reference in New Issue
Block a user