@@ -69,8 +69,8 @@ public function handleGetAssetUrlEvent(GetAssetUrlEvent $event)
69
69
// If we're passed in null, make a dummy AssetTransform model
70
70
if (empty ($ transform )) {
71
71
$ transform = new AssetTransform ([
72
- 'height ' => $ asset ->height ,
73
- 'width ' => $ asset ->width ,
72
+ 'height ' => $ asset ->height ,
73
+ 'width ' => $ asset ->width ,
74
74
'interlace ' => 'line ' ,
75
75
]);
76
76
}
@@ -209,14 +209,16 @@ public function optimizeImage(AssetTransformIndex $index, string $tempPath)
209
209
// Get the active processors for the transform format
210
210
$ activeImageProcessors = $ settings ->activeImageProcessors ;
211
211
$ fileFormat = $ index ->detectedFormat ;
212
+ // Special-case for 'jpeg'
213
+ if ($ fileFormat === 'jpeg ' ) {
214
+ $ fileFormat = 'jpg ' ;
215
+ }
212
216
if (!empty ($ activeImageProcessors [$ fileFormat ])) {
213
217
// Iterate through all of the processors for this format
214
218
$ imageProcessors = $ settings ->imageProcessors ;
215
- if (!empty ($ activeImageProcessors [$ fileFormat ])) {
216
- foreach ($ activeImageProcessors [$ fileFormat ] as $ processor ) {
217
- if (!empty ($ processor ) && !empty ($ imageProcessors [$ processor ])) {
218
- $ this ->executeImageProcessor ($ imageProcessors [$ processor ], $ tempPath );
219
- }
219
+ foreach ($ activeImageProcessors [$ fileFormat ] as $ processor ) {
220
+ if (!empty ($ processor ) && !empty ($ imageProcessors [$ processor ])) {
221
+ $ this ->executeImageProcessor ($ imageProcessors [$ processor ], $ tempPath );
220
222
}
221
223
}
222
224
}
@@ -255,58 +257,60 @@ public function createImageVariants(AssetTransformIndex $index, Asset $asset, st
255
257
// Get the active image variant creators
256
258
$ activeImageVariantCreators = $ settings ->activeImageVariantCreators ;
257
259
$ fileFormat = $ index ->detectedFormat ?? $ index ->format ;
260
+ // Special-case for 'jpeg'
261
+ if ($ fileFormat === 'jpeg ' ) {
262
+ $ fileFormat = 'jpg ' ;
263
+ }
258
264
if (!empty ($ activeImageVariantCreators [$ fileFormat ])) {
259
265
// Iterate through all of the image variant creators for this format
260
266
$ imageVariantCreators = $ settings ->imageVariantCreators ;
261
- if (!empty ($ activeImageVariantCreators [$ fileFormat ])) {
262
- foreach ($ activeImageVariantCreators [$ fileFormat ] as $ variantCreator ) {
263
- if (!empty ($ variantCreator ) && !empty ($ imageVariantCreators [$ variantCreator ])) {
264
- // Create the image variant in a temporary folder
265
- $ generalConfig = Craft::$ app ->getConfig ()->getGeneral ();
266
- $ quality = $ index ->transform ->quality ?: $ generalConfig ->defaultImageQuality ;
267
- $ outputPath = $ this ->executeVariantCreator (
268
- $ imageVariantCreators [$ variantCreator ],
269
- $ tempPath ,
270
- $ quality
271
- );
267
+ foreach ($ activeImageVariantCreators [$ fileFormat ] as $ variantCreator ) {
268
+ if (!empty ($ variantCreator ) && !empty ($ imageVariantCreators [$ variantCreator ])) {
269
+ // Create the image variant in a temporary folder
270
+ $ generalConfig = Craft::$ app ->getConfig ()->getGeneral ();
271
+ $ quality = $ index ->transform ->quality ?: $ generalConfig ->defaultImageQuality ;
272
+ $ outputPath = $ this ->executeVariantCreator (
273
+ $ imageVariantCreators [$ variantCreator ],
274
+ $ tempPath ,
275
+ $ quality
276
+ );
272
277
273
- if (!empty ($ outputPath )) {
274
- // Get info on the original and the created variant
275
- $ originalFileSize = @filesize ($ tempPath );
276
- $ variantFileSize = @filesize ($ outputPath );
277
-
278
- Craft::info (
279
- pathinfo ($ tempPath , PATHINFO_FILENAME )
280
- .'. '
281
- .pathinfo ($ tempPath , PATHINFO_EXTENSION )
282
- .' -> '
283
- .pathinfo ($ outputPath , PATHINFO_FILENAME )
284
- .'. '
285
- .pathinfo ($ outputPath , PATHINFO_EXTENSION )
286
- .' -> '
287
- .Craft::t ('image-optimize ' , 'Original ' )
288
- .': '
289
- .$ this ->humanFileSize ($ originalFileSize , 1 )
290
- .', '
291
- .Craft::t ('image-optimize ' , 'Variant ' )
292
- .': '
293
- .$ this ->humanFileSize ($ variantFileSize , 1 )
294
- .' -> '
295
- .Craft::t ('image-optimize ' , 'Savings ' )
296
- .': '
297
- .number_format (abs (100 - (($ variantFileSize * 100 ) / $ originalFileSize )), 1 )
298
- .'% ' ,
299
- __METHOD__
300
- );
278
+ if (!empty ($ outputPath )) {
279
+ // Get info on the original and the created variant
280
+ $ originalFileSize = @filesize ($ tempPath );
281
+ $ variantFileSize = @filesize ($ outputPath );
301
282
302
- // Copy the image variant into place
303
- $ this ->copyImageVariantToVolume (
304
- $ imageVariantCreators [$ variantCreator ],
305
- $ asset ,
306
- $ index ,
307
- $ outputPath
308
- );
309
- }
283
+ Craft::info (
284
+ pathinfo ($ tempPath , PATHINFO_FILENAME )
285
+ .'. '
286
+ .pathinfo ($ tempPath , PATHINFO_EXTENSION )
287
+ .' -> '
288
+ .pathinfo ($ outputPath , PATHINFO_FILENAME )
289
+ .'. '
290
+ .pathinfo ($ outputPath , PATHINFO_EXTENSION )
291
+ .' -> '
292
+ .Craft::t ('image-optimize ' , 'Original ' )
293
+ .': '
294
+ .$ this ->humanFileSize ($ originalFileSize , 1 )
295
+ .', '
296
+ .Craft::t ('image-optimize ' , 'Variant ' )
297
+ .': '
298
+ .$ this ->humanFileSize ($ variantFileSize , 1 )
299
+ .' -> '
300
+ .Craft::t ('image-optimize ' , 'Savings ' )
301
+ .': '
302
+ .number_format (abs (100 - (($ variantFileSize * 100 ) / $ originalFileSize )), 1 )
303
+ .'% ' ,
304
+ __METHOD__
305
+ );
306
+
307
+ // Copy the image variant into place
308
+ $ this ->copyImageVariantToVolume (
309
+ $ imageVariantCreators [$ variantCreator ],
310
+ $ asset ,
311
+ $ index ,
312
+ $ outputPath
313
+ );
310
314
}
311
315
}
312
316
}
@@ -332,9 +336,9 @@ public function getActiveImageProcessors(): array
332
336
if (!empty ($ imageProcessors [$ processor ])) {
333
337
$ thisImageProcessor = $ imageProcessors [$ processor ];
334
338
$ result [] = [
335
- 'format ' => $ imageFormat ,
336
- 'creator ' => $ processor ,
337
- 'command ' => $ thisImageProcessor ['commandPath ' ]
339
+ 'format ' => $ imageFormat ,
340
+ 'creator ' => $ processor ,
341
+ 'command ' => $ thisImageProcessor ['commandPath ' ]
338
342
.' '
339
343
.$ thisImageProcessor ['commandOptions ' ],
340
344
'installed ' => is_file ($ thisImageProcessor ['commandPath ' ]),
@@ -364,9 +368,9 @@ public function getActiveVariantCreators(): array
364
368
if (!empty ($ imageVariantCreators [$ variantCreator ])) {
365
369
$ thisVariantCreator = $ imageVariantCreators [$ variantCreator ];
366
370
$ result [] = [
367
- 'format ' => $ imageFormat ,
368
- 'creator ' => $ variantCreator ,
369
- 'command ' => $ thisVariantCreator ['commandPath ' ]
371
+ 'format ' => $ imageFormat ,
372
+ 'creator ' => $ variantCreator ,
373
+ 'command ' => $ thisVariantCreator ['commandPath ' ]
370
374
.' '
371
375
.$ thisVariantCreator ['commandOptions ' ],
372
376
'installed ' => is_file ($ thisVariantCreator ['commandPath ' ]),
@@ -577,9 +581,9 @@ protected function cleanupImageVariants(Asset $asset, AssetTransformIndex $trans
577
581
}
578
582
try {
579
583
$ variantPath = $ asset ->getFolder ()->path .$ assetTransforms ->getTransformSubpath (
580
- $ asset ,
581
- $ transformIndex
582
- );
584
+ $ asset ,
585
+ $ transformIndex
586
+ );
583
587
} catch (InvalidConfigException $ e ) {
584
588
$ variantPath = '' ;
585
589
Craft::error (
0 commit comments