1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ImageOptimize plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* Automatically optimize images after they've been transformed |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2017 nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace nystudio107\imageoptimize\services; |
12
|
|
|
|
13
|
|
|
use nystudio107\imageoptimize\ImageOptimize; |
14
|
|
|
use nystudio107\imageoptimize\helpers\PluginTemplate as PluginTemplateHelper; |
15
|
|
|
use nystudio107\imageoptimize\imagetransforms\CraftImageTransform; |
16
|
|
|
use nystudio107\imageoptimize\imagetransforms\ImageTransform; |
17
|
|
|
use nystudio107\imageoptimize\imagetransforms\ImageTransformInterface; |
18
|
|
|
use nystudio107\imageoptimizeimgix\imagetransforms\ImgixImageTransform; |
19
|
|
|
use nystudio107\imageoptimizethumbor\imagetransforms\ThumborImageTransform; |
20
|
|
|
use nystudio107\imageoptimizesharp\imagetransforms\SharpImageTransform; |
21
|
|
|
|
22
|
|
|
use Craft; |
23
|
|
|
use craft\base\Component; |
24
|
|
|
use craft\base\Image; |
25
|
|
|
use craft\elements\Asset; |
26
|
|
|
use craft\errors\ImageException; |
27
|
|
|
use craft\errors\VolumeException; |
28
|
|
|
use craft\events\AssetTransformImageEvent; |
29
|
|
|
use craft\events\GetAssetThumbUrlEvent; |
30
|
|
|
use craft\events\GetAssetUrlEvent; |
31
|
|
|
use craft\events\GenerateTransformEvent; |
32
|
|
|
use craft\events\RegisterComponentTypesEvent; |
33
|
|
|
use craft\helpers\Assets as AssetsHelper; |
34
|
|
|
use craft\helpers\Component as ComponentHelper; |
35
|
|
|
use craft\helpers\FileHelper; |
36
|
|
|
use craft\helpers\Html; |
37
|
|
|
use craft\helpers\Image as ImageHelper; |
38
|
|
|
use craft\image\Raster; |
39
|
|
|
use craft\models\AssetTransform; |
40
|
|
|
use craft\models\AssetTransformIndex; |
41
|
|
|
|
42
|
|
|
use mikehaertl\shellcommand\Command as ShellCommand; |
43
|
|
|
|
44
|
|
|
use yii\base\InvalidConfigException; |
45
|
|
|
|
46
|
|
|
/** @noinspection MissingPropertyAnnotationsInspection */ |
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
|
|
|
|
49
|
|
|
* @author nystudio107 |
|
|
|
|
50
|
|
|
* @package ImageOptimize |
|
|
|
|
51
|
|
|
* @since 1.0.0 |
|
|
|
|
52
|
|
|
*/ |
|
|
|
|
53
|
|
|
class Optimize extends Component |
54
|
|
|
{ |
55
|
|
|
// Constants |
56
|
|
|
// ========================================================================= |
57
|
|
|
|
58
|
|
|
/** |
|
|
|
|
59
|
|
|
* @event RegisterComponentTypesEvent The event that is triggered when registering |
60
|
|
|
* Image Transform types |
61
|
|
|
* |
62
|
|
|
* Image Transform types must implement [[ImageTransformInterface]]. [[ImageTransform]] |
63
|
|
|
* provides a base implementation. |
64
|
|
|
* |
65
|
|
|
* ```php |
66
|
|
|
* use nystudio107\imageoptimize\services\Optimize; |
67
|
|
|
* use craft\events\RegisterComponentTypesEvent; |
68
|
|
|
* use yii\base\Event; |
69
|
|
|
* |
70
|
|
|
* Event::on(Optimize::class, |
71
|
|
|
* Optimize::EVENT_REGISTER_IMAGE_TRANSFORM_TYPES, |
72
|
|
|
* function(RegisterComponentTypesEvent $event) { |
73
|
|
|
* $event->types[] = MyImageTransform::class; |
74
|
|
|
* } |
75
|
|
|
* ); |
76
|
|
|
* ``` |
77
|
|
|
*/ |
78
|
|
|
const EVENT_REGISTER_IMAGE_TRANSFORM_TYPES = 'registerImageTransformTypes'; |
79
|
|
|
|
80
|
|
|
const DEFAULT_IMAGE_TRANSFORM_TYPES = [ |
81
|
|
|
CraftImageTransform::class, |
82
|
|
|
ImgixImageTransform::class, |
83
|
|
|
SharpImageTransform::class, |
84
|
|
|
ThumborImageTransform::class, |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
// Public Methods |
88
|
|
|
// ========================================================================= |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns all available field type classes. |
92
|
|
|
* |
93
|
|
|
* @return string[] The available field type classes |
94
|
|
|
*/ |
95
|
|
|
public function getAllImageTransformTypes(): array |
96
|
|
|
{ |
97
|
|
|
$imageTransformTypes = array_unique(array_merge( |
|
|
|
|
98
|
|
|
ImageOptimize::$plugin->getSettings()->defaultImageTransformTypes ?? [], |
99
|
|
|
self::DEFAULT_IMAGE_TRANSFORM_TYPES |
100
|
|
|
), SORT_REGULAR); |
|
|
|
|
101
|
|
|
|
102
|
|
|
$event = new RegisterComponentTypesEvent([ |
|
|
|
|
103
|
|
|
'types' => $imageTransformTypes |
104
|
|
|
]); |
|
|
|
|
105
|
|
|
$this->trigger(self::EVENT_REGISTER_IMAGE_TRANSFORM_TYPES, $event); |
106
|
|
|
|
107
|
|
|
return $event->types; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Creates an Image Transform with a given config. |
112
|
|
|
* |
113
|
|
|
* @param mixed $config The Image Transform’s class name, or its config, |
114
|
|
|
* with a `type` value and optionally a `settings` value |
115
|
|
|
* |
116
|
|
|
* @return null|ImageTransformInterface The Image Transform |
117
|
|
|
*/ |
118
|
|
|
public function createImageTransformType($config): ImageTransformInterface |
119
|
|
|
{ |
120
|
|
|
if (is_string($config)) { |
121
|
|
|
$config = ['type' => $config]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
try { |
125
|
|
|
/** @var ImageTransform $imageTransform */ |
|
|
|
|
126
|
|
|
$imageTransform = ComponentHelper::createComponent($config, ImageTransformInterface::class); |
127
|
|
|
} catch (\Throwable $e) { |
128
|
|
|
$imageTransform = null; |
129
|
|
|
Craft::error($e->getMessage(), __METHOD__); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $imageTransform; |
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Handle responding to EVENT_GET_ASSET_URL events |
137
|
|
|
* |
138
|
|
|
* @param GetAssetUrlEvent $event |
|
|
|
|
139
|
|
|
* |
140
|
|
|
* @return null|string |
141
|
|
|
* @throws InvalidConfigException |
142
|
|
|
*/ |
143
|
|
|
public function handleGetAssetUrlEvent(GetAssetUrlEvent $event) |
144
|
|
|
{ |
145
|
|
|
Craft::beginProfile('handleGetAssetUrlEvent', __METHOD__); |
146
|
|
|
$url = null; |
147
|
|
|
if (!ImageOptimize::$plugin->transformMethod instanceof CraftImageTransform) { |
148
|
|
|
$asset = $event->asset; |
149
|
|
|
$transform = $event->transform; |
150
|
|
|
// If the transform is empty in some regard, normalize it to null |
151
|
|
|
if (empty($transform)) { |
152
|
|
|
$transform = null; |
153
|
|
|
} |
154
|
|
|
// If there's no transform requested, and we can't manipulate the image anyway, just return the URL |
155
|
|
|
if ($transform === null |
156
|
|
|
&& !ImageHelper::canManipulateAsImage(pathinfo($asset->filename, PATHINFO_EXTENSION))) { |
|
|
|
|
157
|
|
|
$volume = $asset->getVolume(); |
158
|
|
|
|
159
|
|
|
return AssetsHelper::generateUrl($volume, $asset); |
160
|
|
|
} |
161
|
|
|
// If we're passed in null, make a dummy AssetTransform model for Thumbor |
162
|
|
|
// For backwards compatibility |
163
|
|
|
if ($transform === null && ImageOptimize::$plugin->transformMethod instanceof ThumborImageTransform) { |
164
|
|
|
$transform = new AssetTransform([ |
|
|
|
|
165
|
|
|
'width' => $asset->width, |
166
|
|
|
'interlace' => 'line', |
167
|
|
|
]); |
|
|
|
|
168
|
|
|
} |
169
|
|
|
// If we're passed an array, make an AssetTransform model out of it |
170
|
|
|
if (\is_array($transform)) { |
171
|
|
|
$transform = new AssetTransform($transform); |
172
|
|
|
} |
173
|
|
|
// If we're passing in a string, look up the asset transform in the db |
174
|
|
|
if (\is_string($transform)) { |
175
|
|
|
$assetTransforms = Craft::$app->getAssetTransforms(); |
176
|
|
|
$transform = $assetTransforms->getTransformByHandle($transform); |
177
|
|
|
} |
178
|
|
|
// If the final format is an SVG, don't attempt to transform it |
179
|
|
|
$finalFormat = empty($transform['format']) ? $asset->getExtension() : $transform['format']; |
180
|
|
|
if ($finalFormat === 'svg') { |
181
|
|
|
return null; |
182
|
|
|
} |
183
|
|
|
// Normalize the extension to lowercase, for some transform methods that require this |
184
|
|
|
if (!empty($transform) && !empty($finalFormat)) { |
185
|
|
|
$format = $transform['format'] ?? null; |
186
|
|
|
$transform['format'] = $format === null ? null : strtolower($finalFormat); |
187
|
|
|
} |
188
|
|
|
// Generate an image transform url |
189
|
|
|
$url = ImageOptimize::$plugin->transformMethod->getTransformUrl( |
190
|
|
|
$asset, |
191
|
|
|
$transform |
192
|
|
|
); |
193
|
|
|
} |
194
|
|
|
Craft::endProfile('handleGetAssetUrlEvent', __METHOD__); |
195
|
|
|
|
196
|
|
|
return $url; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Handle responding to EVENT_GET_ASSET_THUMB_URL events |
201
|
|
|
* |
202
|
|
|
* @param GetAssetThumbUrlEvent $event |
|
|
|
|
203
|
|
|
* |
204
|
|
|
* @return null|string |
205
|
|
|
*/ |
206
|
|
|
public function handleGetAssetThumbUrlEvent(GetAssetThumbUrlEvent $event) |
207
|
|
|
{ |
208
|
|
|
Craft::beginProfile('handleGetAssetThumbUrlEvent', __METHOD__); |
209
|
|
|
$url = $event->url; |
210
|
|
|
if (!ImageOptimize::$plugin->transformMethod instanceof CraftImageTransform) { |
211
|
|
|
$asset = $event->asset; |
212
|
|
|
if (ImageHelper::canManipulateAsImage($asset->getExtension())) { |
213
|
|
|
$transform = new AssetTransform([ |
|
|
|
|
214
|
|
|
'width' => $event->width, |
215
|
|
|
'height' => $event->height, |
|
|
|
|
216
|
|
|
'interlace' => 'line', |
217
|
|
|
]); |
|
|
|
|
218
|
|
|
/** @var ImageTransform $transformMethod */ |
|
|
|
|
219
|
|
|
$transformMethod = ImageOptimize::$plugin->transformMethod; |
220
|
|
|
// If the final format is an SVG, don't attempt to transform it |
221
|
|
|
$finalFormat = empty($transform['format']) ? $asset->getExtension() : $transform['format']; |
222
|
|
|
if ($finalFormat === 'svg') { |
223
|
|
|
return null; |
224
|
|
|
} |
225
|
|
|
// Normalize the extension to lowercase, for some transform methods that require this |
226
|
|
|
if ($transform !== null && !empty($finalFormat)) { |
227
|
|
|
$transform['format'] = strtolower($finalFormat); |
228
|
|
|
} |
229
|
|
|
// Generate an image transform url |
230
|
|
|
if ($transformMethod->hasProperty('generateTransformsBeforePageLoad')) { |
231
|
|
|
$transformMethod->generateTransformsBeforePageLoad = $event->generate; |
|
|
|
|
232
|
|
|
} |
233
|
|
|
$url = $transformMethod->getTransformUrl($asset, $transform); |
|
|
|
|
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
Craft::endProfile('handleGetAssetThumbUrlEvent', __METHOD__); |
237
|
|
|
|
238
|
|
|
return $url; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Returns whether `.webp` is a format supported by the server |
243
|
|
|
* |
244
|
|
|
* @return bool |
245
|
|
|
*/ |
246
|
|
|
public function serverSupportsWebP(): bool |
247
|
|
|
{ |
248
|
|
|
$result = false; |
249
|
|
|
$variantCreators = ImageOptimize::$plugin->optimize->getActiveVariantCreators(); |
250
|
|
|
foreach ($variantCreators as $variantCreator) { |
251
|
|
|
if ($variantCreator['creator'] === 'cwebp' && $variantCreator['installed']) { |
252
|
|
|
$result = true; |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
return $result; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Render the LazySizes fallback JS |
261
|
|
|
* |
262
|
|
|
* @param array $scriptAttrs |
|
|
|
|
263
|
|
|
* @param array $variables |
|
|
|
|
264
|
|
|
* @return string |
|
|
|
|
265
|
|
|
*/ |
266
|
|
|
public function renderLazySizesFallbackJs($scriptAttrs = [], $variables = []) |
267
|
|
|
{ |
268
|
|
|
$minifier = 'minify'; |
269
|
|
|
if ($scriptAttrs === null) { |
|
|
|
|
270
|
|
|
$minifier = 'jsMin'; |
271
|
|
|
} |
272
|
|
|
$vars = array_merge([ |
|
|
|
|
273
|
|
|
'scriptSrc' => 'https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.3.0/lazysizes.min.js', |
274
|
|
|
], |
275
|
|
|
$variables, |
276
|
|
|
); |
277
|
|
|
$content = PluginTemplateHelper::renderPluginTemplate( |
278
|
|
|
'frontend/lazysizes-fallback-js', |
279
|
|
|
$vars, |
280
|
|
|
$minifier |
281
|
|
|
); |
282
|
|
|
$content = (string)$content; |
283
|
|
|
if ($scriptAttrs !== null) { |
|
|
|
|
284
|
|
|
$attrs = array_merge([ |
|
|
|
|
285
|
|
|
], |
286
|
|
|
$scriptAttrs, |
287
|
|
|
); |
288
|
|
|
$content = Html::tag('script', $content, $scriptAttrs); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
return $content; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Render the LazySizes fallback JS |
296
|
|
|
* |
297
|
|
|
* @param array $scriptAttrs |
|
|
|
|
298
|
|
|
* @param array $variables |
|
|
|
|
299
|
|
|
* @return string |
|
|
|
|
300
|
|
|
*/ |
301
|
|
|
public function renderLazySizesJs($scriptAttrs = [], $variables = []) |
302
|
|
|
{ |
303
|
|
|
$minifier = 'minify'; |
304
|
|
|
if ($scriptAttrs === null) { |
|
|
|
|
305
|
|
|
$minifier = 'jsMin'; |
306
|
|
|
} |
307
|
|
|
$vars = array_merge([ |
|
|
|
|
308
|
|
|
'scriptSrc' => 'https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.3.0/lazysizes.min.js', |
309
|
|
|
], |
|
|
|
|
310
|
|
|
$variables, |
311
|
|
|
); |
312
|
|
|
$content = PluginTemplateHelper::renderPluginTemplate( |
313
|
|
|
'frontend/lazysizes-js', |
314
|
|
|
$vars, |
315
|
|
|
$minifier |
316
|
|
|
); |
317
|
|
|
$content = (string)$content; |
318
|
|
|
if ($scriptAttrs !== null) { |
|
|
|
|
319
|
|
|
$attrs = array_merge([ |
|
|
|
|
320
|
|
|
], |
|
|
|
|
321
|
|
|
$scriptAttrs, |
322
|
|
|
); |
323
|
|
|
$content = Html::tag('script', $content, $scriptAttrs); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
return $content; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Handle responding to EVENT_GENERATE_TRANSFORM events |
331
|
|
|
* |
332
|
|
|
* @param GenerateTransformEvent $event |
|
|
|
|
333
|
|
|
* |
334
|
|
|
* @return null|string |
335
|
|
|
*/ |
336
|
|
|
public function handleGenerateTransformEvent(GenerateTransformEvent $event) |
337
|
|
|
{ |
338
|
|
|
Craft::beginProfile('handleGenerateTransformEvent', __METHOD__); |
339
|
|
|
$tempPath = null; |
340
|
|
|
|
341
|
|
|
// Only do this for local Craft transforms |
342
|
|
|
if (ImageOptimize::$plugin->transformMethod instanceof CraftImageTransform && $event->asset !== null) { |
343
|
|
|
// Apply any filters to the image |
344
|
|
|
if ($event->transformIndex->transform !== null) { |
345
|
|
|
$this->applyFiltersToImage($event->transformIndex->transform, $event->asset, $event->image); |
346
|
|
|
} |
347
|
|
|
// Save the transformed image to a temp file |
348
|
|
|
$tempPath = $this->saveTransformToTempFile( |
349
|
|
|
$event->transformIndex, |
350
|
|
|
$event->image |
351
|
|
|
); |
352
|
|
|
$originalFileSize = @filesize($tempPath); |
353
|
|
|
// Optimize the image |
354
|
|
|
$this->optimizeImage( |
355
|
|
|
$event->transformIndex, |
356
|
|
|
$tempPath |
357
|
|
|
); |
358
|
|
|
clearstatcache(true, $tempPath); |
359
|
|
|
// Log the results of the image optimization |
360
|
|
|
$optimizedFileSize = @filesize($tempPath); |
361
|
|
|
$index = $event->transformIndex; |
362
|
|
|
Craft::info( |
363
|
|
|
pathinfo($index->filename, PATHINFO_FILENAME) |
|
|
|
|
364
|
|
|
.'.' |
365
|
|
|
.$index->detectedFormat |
366
|
|
|
.' -> ' |
367
|
|
|
.Craft::t('image-optimize', 'Original') |
368
|
|
|
.': ' |
369
|
|
|
.$this->humanFileSize($originalFileSize, 1) |
370
|
|
|
.', ' |
371
|
|
|
.Craft::t('image-optimize', 'Optimized') |
372
|
|
|
.': ' |
373
|
|
|
.$this->humanFileSize($optimizedFileSize, 1) |
374
|
|
|
.' -> ' |
375
|
|
|
.Craft::t('image-optimize', 'Savings') |
376
|
|
|
.': ' |
377
|
|
|
.number_format(abs(100 - (($optimizedFileSize * 100) / $originalFileSize)), 1) |
378
|
|
|
.'%', |
379
|
|
|
__METHOD__ |
380
|
|
|
); |
381
|
|
|
// Create any image variants |
382
|
|
|
$this->createImageVariants( |
383
|
|
|
$event->transformIndex, |
384
|
|
|
$event->asset, |
385
|
|
|
$tempPath |
386
|
|
|
); |
387
|
|
|
} |
388
|
|
|
Craft::endProfile('handleGenerateTransformEvent', __METHOD__); |
389
|
|
|
|
390
|
|
|
return $tempPath; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Handle cleaning up any variant creator images |
395
|
|
|
* |
396
|
|
|
* @param AssetTransformImageEvent $event |
|
|
|
|
397
|
|
|
*/ |
|
|
|
|
398
|
|
|
public function handleAfterDeleteTransformsEvent(AssetTransformImageEvent $event) |
399
|
|
|
{ |
400
|
|
|
$settings = ImageOptimize::$plugin->getSettings(); |
|
|
|
|
401
|
|
|
// Only do this for local Craft transforms |
402
|
|
|
if (ImageOptimize::$plugin->transformMethod instanceof CraftImageTransform && $event->asset !== null) { |
403
|
|
|
$this->cleanupImageVariants($event->asset, $event->transformIndex); |
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Save out the image to a temp file |
409
|
|
|
* |
410
|
|
|
* @param AssetTransformIndex $index |
|
|
|
|
411
|
|
|
* @param Image $image |
|
|
|
|
412
|
|
|
* |
413
|
|
|
* @return string |
414
|
|
|
*/ |
415
|
|
|
public function saveTransformToTempFile(AssetTransformIndex $index, Image $image): string |
416
|
|
|
{ |
417
|
|
|
$tempFilename = uniqid(pathinfo($index->filename, PATHINFO_FILENAME), true).'.'.$index->detectedFormat; |
|
|
|
|
418
|
|
|
$tempPath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$tempFilename; |
419
|
|
|
try { |
420
|
|
|
$image->saveAs($tempPath); |
421
|
|
|
} catch (ImageException $e) { |
422
|
|
|
Craft::error('Transformed image save failed: '.$e->getMessage(), __METHOD__); |
423
|
|
|
} |
424
|
|
|
Craft::info('Transformed image saved to: '.$tempPath, __METHOD__); |
425
|
|
|
|
426
|
|
|
return $tempPath; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* Run any image post-processing/optimization on the image file |
431
|
|
|
* |
432
|
|
|
* @param AssetTransformIndex $index |
|
|
|
|
433
|
|
|
* @param string $tempPath |
|
|
|
|
434
|
|
|
*/ |
|
|
|
|
435
|
|
|
public function optimizeImage(AssetTransformIndex $index, string $tempPath) |
436
|
|
|
{ |
437
|
|
|
Craft::beginProfile('optimizeImage', __METHOD__); |
438
|
|
|
$settings = ImageOptimize::$plugin->getSettings(); |
439
|
|
|
// Get the active processors for the transform format |
440
|
|
|
$activeImageProcessors = $settings->activeImageProcessors; |
441
|
|
|
$fileFormat = $index->detectedFormat; |
442
|
|
|
// Special-case for 'jpeg' |
443
|
|
|
if ($fileFormat === 'jpeg') { |
444
|
|
|
$fileFormat = 'jpg'; |
445
|
|
|
} |
446
|
|
|
if (!empty($activeImageProcessors[$fileFormat])) { |
447
|
|
|
// Iterate through all of the processors for this format |
448
|
|
|
$imageProcessors = $settings->imageProcessors; |
449
|
|
|
foreach ($activeImageProcessors[$fileFormat] as $processor) { |
450
|
|
|
if (!empty($processor) && !empty($imageProcessors[$processor])) { |
451
|
|
|
$this->executeImageProcessor($imageProcessors[$processor], $tempPath); |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
Craft::endProfile('optimizeImage', __METHOD__); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Translate bytes into something human-readable |
460
|
|
|
* |
461
|
|
|
* @param $bytes |
|
|
|
|
462
|
|
|
* @param int $decimals |
|
|
|
|
463
|
|
|
* |
464
|
|
|
* @return string |
465
|
|
|
*/ |
466
|
|
|
public function humanFileSize($bytes, $decimals = 1): string |
467
|
|
|
{ |
468
|
|
|
$oldSize = Craft::$app->formatter->sizeFormatBase; |
469
|
|
|
Craft::$app->formatter->sizeFormatBase = 1000; |
470
|
|
|
$result = Craft::$app->formatter->asShortSize($bytes, $decimals); |
471
|
|
|
Craft::$app->formatter->sizeFormatBase = $oldSize; |
472
|
|
|
|
473
|
|
|
return $result; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* Create any image variants for the image file |
478
|
|
|
* |
479
|
|
|
* @param AssetTransformIndex $index |
|
|
|
|
480
|
|
|
* @param Asset $asset |
|
|
|
|
481
|
|
|
* @param string $tempPath |
|
|
|
|
482
|
|
|
*/ |
|
|
|
|
483
|
|
|
public function createImageVariants(AssetTransformIndex $index, Asset $asset, string $tempPath) |
484
|
|
|
{ |
485
|
|
|
Craft::beginProfile('createImageVariants', __METHOD__); |
486
|
|
|
$settings = ImageOptimize::$plugin->getSettings(); |
487
|
|
|
// Get the active image variant creators |
488
|
|
|
$activeImageVariantCreators = $settings->activeImageVariantCreators; |
489
|
|
|
$fileFormat = $index->detectedFormat ?? $index->format; |
490
|
|
|
// Special-case for 'jpeg' |
491
|
|
|
if ($fileFormat === 'jpeg') { |
492
|
|
|
$fileFormat = 'jpg'; |
493
|
|
|
} |
494
|
|
|
if (!empty($activeImageVariantCreators[$fileFormat])) { |
495
|
|
|
// Iterate through all of the image variant creators for this format |
496
|
|
|
$imageVariantCreators = $settings->imageVariantCreators; |
497
|
|
|
foreach ($activeImageVariantCreators[$fileFormat] as $variantCreator) { |
498
|
|
|
if (!empty($variantCreator) && !empty($imageVariantCreators[$variantCreator])) { |
499
|
|
|
// Create the image variant in a temporary folder |
500
|
|
|
$generalConfig = Craft::$app->getConfig()->getGeneral(); |
501
|
|
|
$quality = $index->transform->quality ?: $generalConfig->defaultImageQuality; |
502
|
|
|
$outputPath = $this->executeVariantCreator( |
503
|
|
|
$imageVariantCreators[$variantCreator], |
504
|
|
|
$tempPath, |
505
|
|
|
$quality |
506
|
|
|
); |
507
|
|
|
|
508
|
|
|
if ($outputPath !== null) { |
509
|
|
|
// Get info on the original and the created variant |
510
|
|
|
$originalFileSize = @filesize($tempPath); |
511
|
|
|
$variantFileSize = @filesize($outputPath); |
512
|
|
|
|
513
|
|
|
Craft::info( |
514
|
|
|
pathinfo($tempPath, PATHINFO_FILENAME) |
|
|
|
|
515
|
|
|
.'.' |
516
|
|
|
.pathinfo($tempPath, PATHINFO_EXTENSION) |
|
|
|
|
517
|
|
|
.' -> ' |
518
|
|
|
.pathinfo($outputPath, PATHINFO_FILENAME) |
|
|
|
|
519
|
|
|
.'.' |
520
|
|
|
.pathinfo($outputPath, PATHINFO_EXTENSION) |
|
|
|
|
521
|
|
|
.' -> ' |
522
|
|
|
.Craft::t('image-optimize', 'Original') |
523
|
|
|
.': ' |
524
|
|
|
.$this->humanFileSize($originalFileSize, 1) |
525
|
|
|
.', ' |
526
|
|
|
.Craft::t('image-optimize', 'Variant') |
527
|
|
|
.': ' |
528
|
|
|
.$this->humanFileSize($variantFileSize, 1) |
529
|
|
|
.' -> ' |
530
|
|
|
.Craft::t('image-optimize', 'Savings') |
531
|
|
|
.': ' |
532
|
|
|
.number_format(abs(100 - (($variantFileSize * 100) / $originalFileSize)), 1) |
533
|
|
|
.'%', |
534
|
|
|
__METHOD__ |
535
|
|
|
); |
536
|
|
|
|
537
|
|
|
// Copy the image variant into place |
538
|
|
|
$this->copyImageVariantToVolume( |
539
|
|
|
$imageVariantCreators[$variantCreator], |
540
|
|
|
$asset, |
541
|
|
|
$index, |
542
|
|
|
$outputPath |
543
|
|
|
); |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
Craft::endProfile('createImageVariants', __METHOD__); |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
/** |
552
|
|
|
* Return an array of active image processors |
553
|
|
|
* |
554
|
|
|
* @return array |
555
|
|
|
*/ |
556
|
|
|
public function getActiveImageProcessors(): array |
557
|
|
|
{ |
558
|
|
|
$result = []; |
559
|
|
|
$settings = ImageOptimize::$plugin->getSettings(); |
560
|
|
|
// Get the active processors for the transform format |
561
|
|
|
$activeImageProcessors = $settings->activeImageProcessors; |
562
|
|
|
foreach ($activeImageProcessors as $imageFormat => $imageProcessor) { |
563
|
|
|
// Iterate through all of the processors for this format |
564
|
|
|
$imageProcessors = $settings->imageProcessors; |
565
|
|
|
foreach ($activeImageProcessors[$imageFormat] as $processor) { |
566
|
|
|
if (!empty($imageProcessors[$processor])) { |
567
|
|
|
$thisImageProcessor = $imageProcessors[$processor]; |
568
|
|
|
$result[] = [ |
569
|
|
|
'format' => $imageFormat, |
570
|
|
|
'creator' => $processor, |
571
|
|
|
'command' => $thisImageProcessor['commandPath'] |
572
|
|
|
.' ' |
573
|
|
|
.$thisImageProcessor['commandOptions'], |
574
|
|
|
'installed' => is_file($thisImageProcessor['commandPath']), |
575
|
|
|
]; |
576
|
|
|
} |
577
|
|
|
} |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
return $result; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* Return an array of active image variant creators |
585
|
|
|
* |
586
|
|
|
* @return array |
587
|
|
|
*/ |
588
|
|
|
public function getActiveVariantCreators(): array |
589
|
|
|
{ |
590
|
|
|
$result = []; |
591
|
|
|
$settings = ImageOptimize::$plugin->getSettings(); |
592
|
|
|
// Get the active image variant creators |
593
|
|
|
$activeImageVariantCreators = $settings->activeImageVariantCreators; |
594
|
|
|
foreach ($activeImageVariantCreators as $imageFormat => $imageCreator) { |
595
|
|
|
// Iterate through all of the image variant creators for this format |
596
|
|
|
$imageVariantCreators = $settings->imageVariantCreators; |
597
|
|
|
foreach ($activeImageVariantCreators[$imageFormat] as $variantCreator) { |
598
|
|
|
if (!empty($imageVariantCreators[$variantCreator])) { |
599
|
|
|
$thisVariantCreator = $imageVariantCreators[$variantCreator]; |
600
|
|
|
$result[] = [ |
601
|
|
|
'format' => $imageFormat, |
602
|
|
|
'creator' => $variantCreator, |
603
|
|
|
'command' => $thisVariantCreator['commandPath'] |
604
|
|
|
.' ' |
605
|
|
|
.$thisVariantCreator['commandOptions'], |
606
|
|
|
'installed' => is_file($thisVariantCreator['commandPath']), |
607
|
|
|
]; |
608
|
|
|
} |
609
|
|
|
} |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
return $result; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
// Protected Methods |
616
|
|
|
// ========================================================================= |
617
|
|
|
|
618
|
|
|
/** @noinspection PhpUnusedParameterInspection |
|
|
|
|
619
|
|
|
* @param AssetTransform $transform |
|
|
|
|
620
|
|
|
* @param Asset $asset |
|
|
|
|
621
|
|
|
* @param Image $image |
|
|
|
|
622
|
|
|
*/ |
|
|
|
|
623
|
|
|
|
624
|
|
|
protected function applyFiltersToImage(AssetTransform $transform, Asset $asset, Image $image) |
625
|
|
|
{ |
626
|
|
|
$settings = ImageOptimize::$plugin->getSettings(); |
627
|
|
|
// Only try to apply filters to Raster images |
628
|
|
|
if ($image instanceof Raster) { |
629
|
|
|
$imagineImage = $image->getImagineImage(); |
630
|
|
|
if ($imagineImage !== null) { |
631
|
|
|
// Handle auto-sharpening scaled down images |
632
|
|
|
if ($settings->autoSharpenScaledImages) { |
633
|
|
|
// See if the image has been scaled >= 50% |
634
|
|
|
$widthScale = $asset->getWidth() / $image->getWidth(); |
635
|
|
|
$heightScale = $asset->getHeight() / $image->getHeight(); |
636
|
|
|
if (($widthScale >= 2.0) || ($heightScale >= 2.0)) { |
637
|
|
|
$imagineImage->effects() |
638
|
|
|
->sharpen(); |
639
|
|
|
Craft::debug( |
640
|
|
|
Craft::t( |
641
|
|
|
'image-optimize', |
642
|
|
|
'Image transform >= 50%, sharpened the transformed image: {name}', |
643
|
|
|
[ |
644
|
|
|
'name' => $asset->title, |
645
|
|
|
] |
646
|
|
|
), |
647
|
|
|
__METHOD__ |
648
|
|
|
); |
649
|
|
|
} |
650
|
|
|
} |
651
|
|
|
} |
652
|
|
|
} |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
|
|
|
|
656
|
|
|
* @param string $tempPath |
|
|
|
|
657
|
|
|
* @param $thisProcessor |
|
|
|
|
658
|
|
|
*/ |
|
|
|
|
659
|
|
|
protected function executeImageProcessor($thisProcessor, string $tempPath) |
660
|
|
|
{ |
661
|
|
|
// Make sure the command exists |
662
|
|
|
if (is_file($thisProcessor['commandPath'])) { |
663
|
|
|
// Set any options for the command |
664
|
|
|
$commandOptions = ''; |
665
|
|
|
if (!empty($thisProcessor['commandOptions'])) { |
666
|
|
|
$commandOptions = ' ' |
667
|
|
|
.$thisProcessor['commandOptions'] |
668
|
|
|
.' '; |
669
|
|
|
} |
670
|
|
|
// Redirect the command output if necessary for this processor |
671
|
|
|
$outputFileFlag = ''; |
672
|
|
|
if (!empty($thisProcessor['commandOutputFileFlag'])) { |
673
|
|
|
$outputFileFlag = ' ' |
674
|
|
|
.$thisProcessor['commandOutputFileFlag'] |
675
|
|
|
.' ' |
676
|
|
|
.escapeshellarg($tempPath) |
677
|
|
|
.' '; |
678
|
|
|
} |
679
|
|
|
// Build the command to execute |
680
|
|
|
$cmd = |
|
|
|
|
681
|
|
|
$thisProcessor['commandPath'] |
682
|
|
|
.$commandOptions |
683
|
|
|
.$outputFileFlag |
684
|
|
|
.escapeshellarg($tempPath); |
685
|
|
|
// Execute the command |
686
|
|
|
$shellOutput = $this->executeShellCommand($cmd); |
687
|
|
|
Craft::info($cmd."\n".$shellOutput, __METHOD__); |
688
|
|
|
} else { |
689
|
|
|
Craft::error( |
690
|
|
|
$thisProcessor['commandPath'] |
691
|
|
|
.' ' |
692
|
|
|
.Craft::t('image-optimize', 'does not exist'), |
693
|
|
|
__METHOD__ |
694
|
|
|
); |
695
|
|
|
} |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
/** |
699
|
|
|
* Execute a shell command |
700
|
|
|
* |
701
|
|
|
* @param string $command |
|
|
|
|
702
|
|
|
* |
703
|
|
|
* @return string |
704
|
|
|
*/ |
705
|
|
|
protected function executeShellCommand(string $command): string |
706
|
|
|
{ |
707
|
|
|
// Create the shell command |
708
|
|
|
$shellCommand = new ShellCommand(); |
709
|
|
|
$shellCommand->setCommand($command); |
710
|
|
|
|
711
|
|
|
// If we don't have proc_open, maybe we've got exec |
712
|
|
|
if (!\function_exists('proc_open') && \function_exists('exec')) { |
713
|
|
|
$shellCommand->useExec = true; |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
// Return the result of the command's output or error |
717
|
|
|
if ($shellCommand->execute()) { |
718
|
|
|
$result = $shellCommand->getOutput(); |
719
|
|
|
} else { |
720
|
|
|
$result = $shellCommand->getError(); |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
return $result; |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
/** |
|
|
|
|
727
|
|
|
* @param $variantCreatorCommand |
|
|
|
|
728
|
|
|
* @param string $tempPath |
|
|
|
|
729
|
|
|
* @param int $imageQuality |
|
|
|
|
730
|
|
|
* |
731
|
|
|
* @return string|null the path to the created variant |
732
|
|
|
*/ |
733
|
|
|
protected function executeVariantCreator($variantCreatorCommand, string $tempPath, int $imageQuality) |
734
|
|
|
{ |
735
|
|
|
$outputPath = $tempPath; |
736
|
|
|
// Make sure the command exists |
737
|
|
|
if (is_file($variantCreatorCommand['commandPath'])) { |
738
|
|
|
// Get the output file for this image variant |
739
|
|
|
$outputPath .= '.'.$variantCreatorCommand['imageVariantExtension']; |
740
|
|
|
// Set any options for the command |
741
|
|
|
$commandOptions = ''; |
742
|
|
|
if (!empty($variantCreatorCommand['commandOptions'])) { |
743
|
|
|
$commandOptions = ' ' |
744
|
|
|
.$variantCreatorCommand['commandOptions'] |
745
|
|
|
.' '; |
746
|
|
|
} |
747
|
|
|
// Redirect the command output if necessary for this variantCreator |
748
|
|
|
$outputFileFlag = ''; |
749
|
|
|
if (!empty($variantCreatorCommand['commandOutputFileFlag'])) { |
750
|
|
|
$outputFileFlag = ' ' |
751
|
|
|
.$variantCreatorCommand['commandOutputFileFlag'] |
752
|
|
|
.' ' |
753
|
|
|
.escapeshellarg($outputPath) |
754
|
|
|
.' '; |
755
|
|
|
} |
756
|
|
|
// Get the quality setting of this transform |
757
|
|
|
$commandQualityFlag = ''; |
758
|
|
|
if (!empty($variantCreatorCommand['commandQualityFlag'])) { |
759
|
|
|
$commandQualityFlag = ' ' |
760
|
|
|
.$variantCreatorCommand['commandQualityFlag'] |
761
|
|
|
.' ' |
762
|
|
|
.$imageQuality |
763
|
|
|
.' '; |
764
|
|
|
} |
765
|
|
|
// Build the command to execute |
766
|
|
|
$cmd = |
|
|
|
|
767
|
|
|
$variantCreatorCommand['commandPath'] |
768
|
|
|
.$commandOptions |
769
|
|
|
.$commandQualityFlag |
770
|
|
|
.$outputFileFlag |
771
|
|
|
.escapeshellarg($tempPath); |
772
|
|
|
// Execute the command |
773
|
|
|
$shellOutput = $this->executeShellCommand($cmd); |
774
|
|
|
Craft::info($cmd."\n".$shellOutput, __METHOD__); |
775
|
|
|
} else { |
776
|
|
|
Craft::error( |
777
|
|
|
$variantCreatorCommand['commandPath'] |
778
|
|
|
.' ' |
779
|
|
|
.Craft::t('image-optimize', 'does not exist'), |
780
|
|
|
__METHOD__ |
781
|
|
|
); |
782
|
|
|
$outputPath = null; |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
return $outputPath; |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
/** |
|
|
|
|
789
|
|
|
* @param Asset $asset |
|
|
|
|
790
|
|
|
* @param AssetTransformIndex $transformIndex |
|
|
|
|
791
|
|
|
*/ |
|
|
|
|
792
|
|
|
protected function cleanupImageVariants(Asset $asset, AssetTransformIndex $transformIndex) |
793
|
|
|
{ |
794
|
|
|
$settings = ImageOptimize::$plugin->getSettings(); |
795
|
|
|
$assetTransforms = Craft::$app->getAssetTransforms(); |
796
|
|
|
// Get the active image variant creators |
797
|
|
|
$activeImageVariantCreators = $settings->activeImageVariantCreators; |
798
|
|
|
$fileFormat = $transformIndex->detectedFormat ?? $transformIndex->format; |
799
|
|
|
if (!empty($activeImageVariantCreators[$fileFormat])) { |
800
|
|
|
// Iterate through all of the image variant creators for this format |
801
|
|
|
$imageVariantCreators = $settings->imageVariantCreators; |
802
|
|
|
if (!empty($activeImageVariantCreators[$fileFormat])) { |
803
|
|
|
foreach ($activeImageVariantCreators[$fileFormat] as $variantCreator) { |
804
|
|
|
if (!empty($variantCreator) && !empty($imageVariantCreators[$variantCreator])) { |
805
|
|
|
// Create the image variant in a temporary folder |
806
|
|
|
$variantCreatorCommand = $imageVariantCreators[$variantCreator]; |
807
|
|
|
try { |
808
|
|
|
$volume = $asset->getVolume(); |
809
|
|
|
} catch (InvalidConfigException $e) { |
810
|
|
|
$volume = null; |
811
|
|
|
Craft::error( |
812
|
|
|
'Asset volume error: '.$e->getMessage(), |
813
|
|
|
__METHOD__ |
814
|
|
|
); |
815
|
|
|
} |
816
|
|
|
try { |
817
|
|
|
$variantPath = $asset->getFolder()->path.$assetTransforms->getTransformSubpath( |
818
|
|
|
$asset, |
819
|
|
|
$transformIndex |
820
|
|
|
); |
821
|
|
|
} catch (InvalidConfigException $e) { |
822
|
|
|
$variantPath = ''; |
823
|
|
|
Craft::error( |
824
|
|
|
'Asset folder does not exist: '.$e->getMessage(), |
825
|
|
|
__METHOD__ |
826
|
|
|
); |
827
|
|
|
} |
828
|
|
|
$variantPath .= '.'.$variantCreatorCommand['imageVariantExtension']; |
829
|
|
|
// Delete the variant file in case it is stale |
830
|
|
|
try { |
831
|
|
|
$volume->deleteFile($variantPath); |
832
|
|
|
} catch (VolumeException $e) { |
833
|
|
|
// We're fine with that. |
834
|
|
|
} |
835
|
|
|
Craft::info( |
836
|
|
|
'Deleted variant: '.$variantPath, |
837
|
|
|
__METHOD__ |
838
|
|
|
); |
839
|
|
|
} |
840
|
|
|
} |
841
|
|
|
} |
842
|
|
|
} |
843
|
|
|
} |
844
|
|
|
|
845
|
|
|
/** |
|
|
|
|
846
|
|
|
* @param $variantCreatorCommand |
|
|
|
|
847
|
|
|
* @param Asset $asset |
|
|
|
|
848
|
|
|
* @param AssetTransformIndex $index |
|
|
|
|
849
|
|
|
* @param $outputPath |
|
|
|
|
850
|
|
|
*/ |
|
|
|
|
851
|
|
|
protected function copyImageVariantToVolume( |
852
|
|
|
$variantCreatorCommand, |
853
|
|
|
Asset $asset, |
854
|
|
|
AssetTransformIndex $index, |
855
|
|
|
$outputPath |
856
|
|
|
) { |
857
|
|
|
// If the image variant creation succeeded, copy it into place |
858
|
|
|
if (!empty($outputPath) && is_file($outputPath)) { |
859
|
|
|
// Figure out the resulting path for the image variant |
860
|
|
|
try { |
861
|
|
|
$volume = $asset->getVolume(); |
862
|
|
|
} catch (InvalidConfigException $e) { |
863
|
|
|
$volume = null; |
864
|
|
|
Craft::error( |
865
|
|
|
'Asset volume error: '.$e->getMessage(), |
866
|
|
|
__METHOD__ |
867
|
|
|
); |
868
|
|
|
} |
869
|
|
|
$assetTransforms = Craft::$app->getAssetTransforms(); |
870
|
|
|
try { |
871
|
|
|
$transformPath = $asset->getFolder()->path.$assetTransforms->getTransformSubpath($asset, $index); |
872
|
|
|
} catch (InvalidConfigException $e) { |
873
|
|
|
$transformPath = ''; |
874
|
|
|
Craft::error( |
875
|
|
|
'Error getting asset folder: '.$e->getMessage(), |
876
|
|
|
__METHOD__ |
877
|
|
|
); |
878
|
|
|
} |
879
|
|
|
$variantPath = $transformPath.'.'.$variantCreatorCommand['imageVariantExtension']; |
880
|
|
|
|
881
|
|
|
// Delete the variant file in case it is stale |
882
|
|
|
try { |
883
|
|
|
$volume->deleteFile($variantPath); |
884
|
|
|
} catch (VolumeException $e) { |
885
|
|
|
// We're fine with that. |
886
|
|
|
} |
887
|
|
|
|
888
|
|
|
Craft::info( |
889
|
|
|
'Variant output path: '.$outputPath.' - Variant path: '.$variantPath, |
890
|
|
|
__METHOD__ |
891
|
|
|
); |
892
|
|
|
|
893
|
|
|
clearstatcache(true, $outputPath); |
894
|
|
|
$stream = @fopen($outputPath, 'rb'); |
895
|
|
|
if ($stream !== false) { |
896
|
|
|
// Now create it |
897
|
|
|
try { |
898
|
|
|
$volume->createFileByStream($variantPath, $stream, []); |
899
|
|
|
} catch (VolumeException $e) { |
900
|
|
|
Craft::error( |
901
|
|
|
Craft::t('image-optimize', 'Failed to create image variant at: ') |
902
|
|
|
.$outputPath, |
903
|
|
|
__METHOD__ |
904
|
|
|
); |
905
|
|
|
} |
906
|
|
|
|
907
|
|
|
FileHelper::unlink($outputPath); |
908
|
|
|
} |
909
|
|
|
} else { |
910
|
|
|
Craft::error( |
911
|
|
|
Craft::t('image-optimize', 'Failed to create image variant at: ') |
912
|
|
|
.$outputPath, |
913
|
|
|
__METHOD__ |
914
|
|
|
); |
915
|
|
|
} |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
/** |
|
|
|
|
919
|
|
|
* @param string $path |
|
|
|
|
920
|
|
|
* @param string $extension |
|
|
|
|
921
|
|
|
* |
922
|
|
|
* @return string |
923
|
|
|
*/ |
924
|
|
|
protected function swapPathExtension(string $path, string $extension): string |
925
|
|
|
{ |
926
|
|
|
$pathParts = pathinfo($path); |
927
|
|
|
$newPath = $pathParts['filename'].'.'.$extension; |
928
|
|
|
if (!empty($pathParts['dirname']) && $pathParts['dirname'] !== '.') { |
929
|
|
|
$newPath = $pathParts['dirname'].DIRECTORY_SEPARATOR.$newPath; |
930
|
|
|
$newPath = preg_replace('#/+#', '/', $newPath); |
931
|
|
|
} |
932
|
|
|
|
933
|
|
|
return $newPath; |
934
|
|
|
} |
935
|
|
|
} |
936
|
|
|
|