PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 3.1.0
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v3.1.0
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 / Imagick / Encoder.php

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

240 lines 6.8 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\Imagick;
4
5 use Intervention\Image\AbstractEncoder;
6 use Intervention\Image\Exception\NotSupportedException;
7
8 class Encoder extends AbstractEncoder
9 {
10 /**
11 * Processes and returns encoded image as JPEG string
12 *
13 * @return string
14 */
15 protected function processJpeg()
16 {
17 $format = 'jpeg';
18 $compression = \Imagick::COMPRESSION_JPEG;
19
20 $imagick = $this->image->getCore();
21 $imagick->setImageBackgroundColor('white');
22 $imagick->setBackgroundColor('white');
23 $imagick = $imagick->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE);
24 $imagick->setFormat($format);
25 $imagick->setImageFormat($format);
26 $imagick->setCompression($compression);
27 $imagick->setImageCompression($compression);
28 $imagick->setCompressionQuality($this->quality);
29 $imagick->setImageCompressionQuality($this->quality);
30
31 return $imagick->getImagesBlob();
32 }
33
34 /**
35 * Processes and returns encoded image as PNG string
36 *
37 * @return string
38 */
39 protected function processPng()
40 {
41 $format = 'png';
42 $compression = \Imagick::COMPRESSION_ZIP;
43
44 $imagick = $this->image->getCore();
45 $imagick->setFormat($format);
46 $imagick->setImageFormat($format);
47 $imagick->setCompression($compression);
48 $imagick->setImageCompression($compression);
49
50 $this->image->mime = image_type_to_mime_type(IMAGETYPE_PNG);
51
52 return $imagick->getImagesBlob();
53 }
54
55 /**
56 * Processes and returns encoded image as GIF string
57 *
58 * @return string
59 */
60 protected function processGif()
61 {
62 $format = 'gif';
63 $compression = \Imagick::COMPRESSION_LZW;
64
65 $imagick = $this->image->getCore();
66 $imagick->setFormat($format);
67 $imagick->setImageFormat($format);
68 $imagick->setCompression($compression);
69 $imagick->setImageCompression($compression);
70
71 $this->image->mime = image_type_to_mime_type(IMAGETYPE_GIF);
72
73 return $imagick->getImagesBlob();
74 }
75
76 protected function processWebp()
77 {
78 if ( ! \Imagick::queryFormats('WEBP')) {
79 throw new NotSupportedException(
80 "Webp format is not supported by Imagick installation."
81 );
82 }
83
84 $format = 'webp';
85 $compression = \Imagick::COMPRESSION_JPEG;
86
87 $imagick = $this->image->getCore();
88 $imagick->setImageBackgroundColor(new \ImagickPixel('transparent'));
89
90 $imagick = $imagick->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE);
91 $imagick->setFormat($format);
92 $imagick->setImageFormat($format);
93 $imagick->setCompression($compression);
94 $imagick->setImageCompression($compression);
95 $imagick->setImageCompressionQuality($this->quality);
96
97 return $imagick->getImagesBlob();
98 }
99
100 /**
101 * Processes and returns encoded image as TIFF string
102 *
103 * @return string
104 */
105 protected function processTiff()
106 {
107 $format = 'tiff';
108 $compression = \Imagick::COMPRESSION_UNDEFINED;
109
110 $imagick = $this->image->getCore();
111 $imagick->setFormat($format);
112 $imagick->setImageFormat($format);
113 $imagick->setCompression($compression);
114 $imagick->setImageCompression($compression);
115 $imagick->setCompressionQuality($this->quality);
116 $imagick->setImageCompressionQuality($this->quality);
117
118 $this->image->mime = image_type_to_mime_type(IMAGETYPE_TIFF_II);
119
120 return $imagick->getImagesBlob();
121 }
122
123 /**
124 * Processes and returns encoded image as BMP string
125 *
126 * @return string
127 */
128 protected function processBmp()
129 {
130 $format = 'bmp';
131 $compression = \Imagick::COMPRESSION_UNDEFINED;
132
133 $imagick = $this->image->getCore();
134 $imagick->setFormat($format);
135 $imagick->setImageFormat($format);
136 $imagick->setCompression($compression);
137 $imagick->setImageCompression($compression);
138
139 $this->image->mime = image_type_to_mime_type(IMAGETYPE_BMP);
140
141 return $imagick->getImagesBlob();
142 }
143
144 /**
145 * Processes and returns encoded image as ICO string
146 *
147 * @return string
148 */
149 protected function processIco()
150 {
151 $format = 'ico';
152 $compression = \Imagick::COMPRESSION_UNDEFINED;
153
154 $imagick = $this->image->getCore();
155 $imagick->setFormat($format);
156 $imagick->setImageFormat($format);
157 $imagick->setCompression($compression);
158 $imagick->setImageCompression($compression);
159
160 $this->image->mime = image_type_to_mime_type(IMAGETYPE_ICO);
161
162 return $imagick->getImagesBlob();
163 }
164
165 /**
166 * Processes and returns encoded image as PSD string
167 *
168 * @return string
169 */
170 protected function processPsd()
171 {
172 $format = 'psd';
173 $compression = \Imagick::COMPRESSION_UNDEFINED;
174
175 $imagick = $this->image->getCore();
176 $imagick->setFormat($format);
177 $imagick->setImageFormat($format);
178 $imagick->setCompression($compression);
179 $imagick->setImageCompression($compression);
180
181 $this->image->mime = image_type_to_mime_type(IMAGETYPE_PSD);
182
183 return $imagick->getImagesBlob();
184 }
185
186 /**
187 * Processes and returns encoded image as AVIF string
188 *
189 * @return string
190 */
191 protected function processAvif()
192 {
193 if ( ! \Imagick::queryFormats('AVIF')) {
194 throw new NotSupportedException(
195 "AVIF format is not supported by Imagick installation."
196 );
197 }
198
199 $format = 'avif';
200 $compression = \Imagick::COMPRESSION_UNDEFINED;
201
202 $imagick = $this->image->getCore();
203 $imagick->setFormat($format);
204 $imagick->setImageFormat($format);
205 $imagick->setCompression($compression);
206 $imagick->setImageCompression($compression);
207 $imagick->setCompressionQuality($this->quality);
208 $imagick->setImageCompressionQuality($this->quality);
209
210 return $imagick->getImagesBlob();
211 }
212
213 /**
214 * Processes and returns encoded image as HEIC string
215 *
216 * @return string
217 */
218 protected function processHeic()
219 {
220 if ( ! \Imagick::queryFormats('HEIC')) {
221 throw new NotSupportedException(
222 "HEIC format is not supported by Imagick installation."
223 );
224 }
225
226 $format = 'heic';
227 $compression = \Imagick::COMPRESSION_UNDEFINED;
228
229 $imagick = $this->image->getCore();
230 $imagick->setFormat($format);
231 $imagick->setImageFormat($format);
232 $imagick->setCompression($compression);
233 $imagick->setImageCompression($compression);
234 $imagick->setCompressionQuality($this->quality);
235 $imagick->setImageCompressionQuality($this->quality);
236
237 return $imagick->getImagesBlob();
238 }
239 }
240