File indexing completed on 2025-01-26 05:29:15

0001 <?php
0002 
0003 namespace Intervention\Image;
0004 
0005 class Response
0006 {
0007     /**
0008      * Image that should be displayed by response
0009      *
0010      * @var Image
0011      */
0012     public $image;
0013 
0014     /**
0015      * Format of displayed image
0016      *
0017      * @var string
0018      */
0019     public $format;
0020 
0021     /**
0022      * Quality of displayed image
0023      *
0024      * @var int
0025      */
0026     public $quality;
0027 
0028     /**
0029      * Creates a new instance of response
0030      *
0031      * @param Image   $image
0032      * @param string  $format
0033      * @param int     $quality
0034      */
0035     public function __construct(Image $image, $format = null, $quality = null)
0036     {
0037         $this->image = $image;
0038         $this->format = $format ? $format : $image->mime;
0039         $this->quality = $quality ? $quality : 90;
0040     }
0041 
0042     /**
0043      * Builds response according to settings
0044      *
0045      * @return mixed
0046      */
0047     public function make()
0048     {
0049         $this->image->encode($this->format, $this->quality);
0050         $data = $this->image->getEncoded();
0051         $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
0052         $length = strlen($data);
0053 
0054         if (function_exists('app') && is_a($app = app(), 'Illuminate\Foundation\Application')) {
0055 
0056             $response = \Illuminate\Support\Facades\Response::make($data);
0057             $response->header('Content-Type', $mime);
0058             $response->header('Content-Length', $length);
0059 
0060         } else {
0061 
0062             header('Content-Type: ' . $mime);
0063             header('Content-Length: ' . $length);
0064             $response = $data;
0065         }
0066 
0067         return $response;
0068     }
0069 }