PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 3.2.1
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v3.2.1
4.1.2 4.1.1 4.1.0 4.0.1 4.0.0 3.3.1 3.3.0 trunk 1.0.0 2.0.0 2.1.0 3.0.0 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8
quickwebp / includes / vendor / intervention / image / src / Intervention / Image / Response.php

Response.php in QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress 3.2.1, at includes/vendor/intervention/image/src/Intervention/Image/Response.php

79 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Intervention\Image;
4
5 use Illuminate\Support\Facades\Response as IlluminateResponse;
6 use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
7
8 class Response
9 {
10 /**
11 * Image that should be displayed by response
12 *
13 * @var Image
14 */
15 public $image;
16
17 /**
18 * Format of displayed image
19 *
20 * @var string
21 */
22 public $format;
23
24 /**
25 * Quality of displayed image
26 *
27 * @var int
28 */
29 public $quality;
30
31 /**
32 * Creates a new instance of response
33 *
34 * @param Image $image
35 * @param string $format
36 * @param int $quality
37 */
38 public function __construct(Image $image, $format = null, $quality = null)
39 {
40 $this->image = $image;
41 $this->format = $format ? $format : $image->mime;
42 $this->quality = $quality ? $quality : 90;
43 }
44
45 /**
46 * Builds response according to settings
47 *
48 * @return mixed
49 */
50 public function make()
51 {
52 $this->image->encode($this->format, $this->quality);
53 $data = $this->image->getEncoded();
54 $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
55 $length = strlen($data);
56
57 if (function_exists('app') && is_a($app = app(), 'Illuminate\Foundation\Application')) {
58
59 $response = IlluminateResponse::make($data);
60 $response->header('Content-Type', $mime);
61 $response->header('Content-Length', $length);
62
63 } elseif (class_exists('\Symfony\Component\HttpFoundation\Response')) {
64
65 $response = new SymfonyResponse($data);
66 $response->headers->set('Content-Type', $mime);
67 $response->headers->set('Content-Length', $length);
68
69 } else {
70
71 header('Content-Type: ' . $mime);
72 header('Content-Length: ' . $length);
73 $response = $data;
74 }
75
76 return $response;
77 }
78 }
79