1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-18 04:38:26 +01:00

renamed and simplified method output to response

This commit is contained in:
Oliver Vogel 2013-12-22 20:39:39 +01:00
parent f591d1c6d0
commit 389417d8d3

View File

@ -1429,23 +1429,29 @@ class Image
break; break;
case 'gif': case 'gif':
case 1: case IMAGETYPE_GIF:
imagegif($this->resource); imagegif($this->resource);
$this->type = IMAGETYPE_GIF;
$this->mime = image_type_to_mime_type(IMAGETYPE_GIF);
break; break;
case 'png': case 'png':
case 3: case IMAGETYPE_PNG:
$quality = round($quality / 11.11111111111); // transform quality to png setting $quality = round($quality / 11.11111111111); // transform quality to png setting
imagealphablending($this->resource, false); imagealphablending($this->resource, false);
imagesavealpha($this->resource, true); imagesavealpha($this->resource, true);
imagepng($this->resource, null, $quality); imagepng($this->resource, null, $quality);
$this->type = IMAGETYPE_PNG;
$this->mime = image_type_to_mime_type(IMAGETYPE_PNG);
break; break;
default: default:
case 'jpg': case 'jpg':
case 'jpeg': case 'jpeg':
case 2: case IMAGETYPE_JPEG:
imagejpeg($this->resource, null, $quality); imagejpeg($this->resource, null, $quality);
$this->type = IMAGETYPE_JPEG;
$this->mime = image_type_to_mime_type(IMAGETYPE_JPEG);
break; break;
} }
@ -1834,40 +1840,26 @@ class Image
/** /**
* Send direct output with proper header * Send direct output with proper header
* *
* @param string $type
* @param integer $quality
* @return string * @return string
*/ */
public function output() public function response($type = null, $quality = 90)
{ {
// Determine image type // encode image in desired type (default: current type)
$type = ''; $this->encode($type, $quality);
// 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 this is a Laravel application, prepare response object
if (function_exists('app') && is_a($app = app(), 'Illuminate\Foundation\Application')) if (function_exists('app') && is_a($app = app(), 'Illuminate\Foundation\Application')) {
{ $response = \Response::make($this->encoded);
$response = \Response::make($this->encode()); $response->header('Content-Type', $this->mime);
$response->header('Content-type', 'image/' . $type);
return $response; return $response;
} }
// If this is not Laravel, set header directly // If this is not Laravel, set header directly
header('Content-type: image/' . $type); header('Content-Type: ' . $this->mime);
return $this->encode(); return $this->encoded;
} }
/** /**