Skip to content

Commit 16bd309

Browse files
committed
Merge branch 'release/1.4.33' into v1
2 parents 8c8577b + a70d971 commit 16bd309

File tree

3 files changed

+73
-64
lines changed

3 files changed

+73
-64
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ImageOptimize Changelog
22

3+
## 1.4.33 - 2018.05.24
4+
### Changed
5+
* Handle JPEGs coming in as both `jpg` & `jpeg` for the detected file format
6+
* Remove vestigal `empty()` checks
7+
38
## 1.4.32 - 2018.05.09
49
### Added
510
* Improved CraftQL support by allowing parameter passing to `src` and `srcUrls`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nystudio107/craft-imageoptimize",
33
"description": "Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like Imgix, with zero template changes.",
44
"type": "craft-plugin",
5-
"version": "1.4.32",
5+
"version": "1.4.33",
66
"keywords": [
77
"craft",
88
"cms",

src/services/Optimize.php

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function handleGetAssetUrlEvent(GetAssetUrlEvent $event)
6969
// If we're passed in null, make a dummy AssetTransform model
7070
if (empty($transform)) {
7171
$transform = new AssetTransform([
72-
'height' => $asset->height,
73-
'width' => $asset->width,
72+
'height' => $asset->height,
73+
'width' => $asset->width,
7474
'interlace' => 'line',
7575
]);
7676
}
@@ -209,14 +209,16 @@ public function optimizeImage(AssetTransformIndex $index, string $tempPath)
209209
// Get the active processors for the transform format
210210
$activeImageProcessors = $settings->activeImageProcessors;
211211
$fileFormat = $index->detectedFormat;
212+
// Special-case for 'jpeg'
213+
if ($fileFormat === 'jpeg') {
214+
$fileFormat = 'jpg';
215+
}
212216
if (!empty($activeImageProcessors[$fileFormat])) {
213217
// Iterate through all of the processors for this format
214218
$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);
220222
}
221223
}
222224
}
@@ -255,58 +257,60 @@ public function createImageVariants(AssetTransformIndex $index, Asset $asset, st
255257
// Get the active image variant creators
256258
$activeImageVariantCreators = $settings->activeImageVariantCreators;
257259
$fileFormat = $index->detectedFormat ?? $index->format;
260+
// Special-case for 'jpeg'
261+
if ($fileFormat === 'jpeg') {
262+
$fileFormat = 'jpg';
263+
}
258264
if (!empty($activeImageVariantCreators[$fileFormat])) {
259265
// Iterate through all of the image variant creators for this format
260266
$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+
);
272277

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);
301282

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+
);
310314
}
311315
}
312316
}
@@ -332,9 +336,9 @@ public function getActiveImageProcessors(): array
332336
if (!empty($imageProcessors[$processor])) {
333337
$thisImageProcessor = $imageProcessors[$processor];
334338
$result[] = [
335-
'format' => $imageFormat,
336-
'creator' => $processor,
337-
'command' => $thisImageProcessor['commandPath']
339+
'format' => $imageFormat,
340+
'creator' => $processor,
341+
'command' => $thisImageProcessor['commandPath']
338342
.' '
339343
.$thisImageProcessor['commandOptions'],
340344
'installed' => is_file($thisImageProcessor['commandPath']),
@@ -364,9 +368,9 @@ public function getActiveVariantCreators(): array
364368
if (!empty($imageVariantCreators[$variantCreator])) {
365369
$thisVariantCreator = $imageVariantCreators[$variantCreator];
366370
$result[] = [
367-
'format' => $imageFormat,
368-
'creator' => $variantCreator,
369-
'command' => $thisVariantCreator['commandPath']
371+
'format' => $imageFormat,
372+
'creator' => $variantCreator,
373+
'command' => $thisVariantCreator['commandPath']
370374
.' '
371375
.$thisVariantCreator['commandOptions'],
372376
'installed' => is_file($thisVariantCreator['commandPath']),
@@ -577,9 +581,9 @@ protected function cleanupImageVariants(Asset $asset, AssetTransformIndex $trans
577581
}
578582
try {
579583
$variantPath = $asset->getFolder()->path.$assetTransforms->getTransformSubpath(
580-
$asset,
581-
$transformIndex
582-
);
584+
$asset,
585+
$transformIndex
586+
);
583587
} catch (InvalidConfigException $e) {
584588
$variantPath = '';
585589
Craft::error(

0 commit comments

Comments
 (0)