Skip to content

Commit

Permalink
Merge branch 'release/1.4.33' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed May 24, 2018
2 parents 8c8577b + a70d971 commit 16bd309
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ImageOptimize Changelog

## 1.4.33 - 2018.05.24
### Changed
* Handle JPEGs coming in as both `jpg` & `jpeg` for the detected file format
* Remove vestigal `empty()` checks

## 1.4.32 - 2018.05.09
### Added
* Improved CraftQL support by allowing parameter passing to `src` and `srcUrls`
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-imageoptimize",
"description": "Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like Imgix, with zero template changes.",
"type": "craft-plugin",
"version": "1.4.32",
"version": "1.4.33",
"keywords": [
"craft",
"cms",
Expand Down
130 changes: 67 additions & 63 deletions src/services/Optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function handleGetAssetUrlEvent(GetAssetUrlEvent $event)
// If we're passed in null, make a dummy AssetTransform model
if (empty($transform)) {
$transform = new AssetTransform([
'height' => $asset->height,
'width' => $asset->width,
'height' => $asset->height,
'width' => $asset->width,
'interlace' => 'line',
]);
}
Expand Down Expand Up @@ -209,14 +209,16 @@ public function optimizeImage(AssetTransformIndex $index, string $tempPath)
// Get the active processors for the transform format
$activeImageProcessors = $settings->activeImageProcessors;
$fileFormat = $index->detectedFormat;
// Special-case for 'jpeg'
if ($fileFormat === 'jpeg') {
$fileFormat = 'jpg';
}
if (!empty($activeImageProcessors[$fileFormat])) {
// Iterate through all of the processors for this format
$imageProcessors = $settings->imageProcessors;
if (!empty($activeImageProcessors[$fileFormat])) {
foreach ($activeImageProcessors[$fileFormat] as $processor) {
if (!empty($processor) && !empty($imageProcessors[$processor])) {
$this->executeImageProcessor($imageProcessors[$processor], $tempPath);
}
foreach ($activeImageProcessors[$fileFormat] as $processor) {
if (!empty($processor) && !empty($imageProcessors[$processor])) {
$this->executeImageProcessor($imageProcessors[$processor], $tempPath);
}
}
}
Expand Down Expand Up @@ -255,58 +257,60 @@ public function createImageVariants(AssetTransformIndex $index, Asset $asset, st
// Get the active image variant creators
$activeImageVariantCreators = $settings->activeImageVariantCreators;
$fileFormat = $index->detectedFormat ?? $index->format;
// Special-case for 'jpeg'
if ($fileFormat === 'jpeg') {
$fileFormat = 'jpg';
}
if (!empty($activeImageVariantCreators[$fileFormat])) {
// Iterate through all of the image variant creators for this format
$imageVariantCreators = $settings->imageVariantCreators;
if (!empty($activeImageVariantCreators[$fileFormat])) {
foreach ($activeImageVariantCreators[$fileFormat] as $variantCreator) {
if (!empty($variantCreator) && !empty($imageVariantCreators[$variantCreator])) {
// Create the image variant in a temporary folder
$generalConfig = Craft::$app->getConfig()->getGeneral();
$quality = $index->transform->quality ?: $generalConfig->defaultImageQuality;
$outputPath = $this->executeVariantCreator(
$imageVariantCreators[$variantCreator],
$tempPath,
$quality
);
foreach ($activeImageVariantCreators[$fileFormat] as $variantCreator) {
if (!empty($variantCreator) && !empty($imageVariantCreators[$variantCreator])) {
// Create the image variant in a temporary folder
$generalConfig = Craft::$app->getConfig()->getGeneral();
$quality = $index->transform->quality ?: $generalConfig->defaultImageQuality;
$outputPath = $this->executeVariantCreator(
$imageVariantCreators[$variantCreator],
$tempPath,
$quality
);

if (!empty($outputPath)) {
// Get info on the original and the created variant
$originalFileSize = @filesize($tempPath);
$variantFileSize = @filesize($outputPath);

Craft::info(
pathinfo($tempPath, PATHINFO_FILENAME)
.'.'
.pathinfo($tempPath, PATHINFO_EXTENSION)
.' -> '
.pathinfo($outputPath, PATHINFO_FILENAME)
.'.'
.pathinfo($outputPath, PATHINFO_EXTENSION)
.' -> '
.Craft::t('image-optimize', 'Original')
.': '
.$this->humanFileSize($originalFileSize, 1)
.', '
.Craft::t('image-optimize', 'Variant')
.': '
.$this->humanFileSize($variantFileSize, 1)
.' -> '
.Craft::t('image-optimize', 'Savings')
.': '
.number_format(abs(100 - (($variantFileSize * 100) / $originalFileSize)), 1)
.'%',
__METHOD__
);
if (!empty($outputPath)) {
// Get info on the original and the created variant
$originalFileSize = @filesize($tempPath);
$variantFileSize = @filesize($outputPath);

// Copy the image variant into place
$this->copyImageVariantToVolume(
$imageVariantCreators[$variantCreator],
$asset,
$index,
$outputPath
);
}
Craft::info(
pathinfo($tempPath, PATHINFO_FILENAME)
.'.'
.pathinfo($tempPath, PATHINFO_EXTENSION)
.' -> '
.pathinfo($outputPath, PATHINFO_FILENAME)
.'.'
.pathinfo($outputPath, PATHINFO_EXTENSION)
.' -> '
.Craft::t('image-optimize', 'Original')
.': '
.$this->humanFileSize($originalFileSize, 1)
.', '
.Craft::t('image-optimize', 'Variant')
.': '
.$this->humanFileSize($variantFileSize, 1)
.' -> '
.Craft::t('image-optimize', 'Savings')
.': '
.number_format(abs(100 - (($variantFileSize * 100) / $originalFileSize)), 1)
.'%',
__METHOD__
);

// Copy the image variant into place
$this->copyImageVariantToVolume(
$imageVariantCreators[$variantCreator],
$asset,
$index,
$outputPath
);
}
}
}
Expand All @@ -332,9 +336,9 @@ public function getActiveImageProcessors(): array
if (!empty($imageProcessors[$processor])) {
$thisImageProcessor = $imageProcessors[$processor];
$result[] = [
'format' => $imageFormat,
'creator' => $processor,
'command' => $thisImageProcessor['commandPath']
'format' => $imageFormat,
'creator' => $processor,
'command' => $thisImageProcessor['commandPath']
.' '
.$thisImageProcessor['commandOptions'],
'installed' => is_file($thisImageProcessor['commandPath']),
Expand Down Expand Up @@ -364,9 +368,9 @@ public function getActiveVariantCreators(): array
if (!empty($imageVariantCreators[$variantCreator])) {
$thisVariantCreator = $imageVariantCreators[$variantCreator];
$result[] = [
'format' => $imageFormat,
'creator' => $variantCreator,
'command' => $thisVariantCreator['commandPath']
'format' => $imageFormat,
'creator' => $variantCreator,
'command' => $thisVariantCreator['commandPath']
.' '
.$thisVariantCreator['commandOptions'],
'installed' => is_file($thisVariantCreator['commandPath']),
Expand Down Expand Up @@ -577,9 +581,9 @@ protected function cleanupImageVariants(Asset $asset, AssetTransformIndex $trans
}
try {
$variantPath = $asset->getFolder()->path.$assetTransforms->getTransformSubpath(
$asset,
$transformIndex
);
$asset,
$transformIndex
);
} catch (InvalidConfigException $e) {
$variantPath = '';
Craft::error(
Expand Down

0 comments on commit 16bd309

Please sign in to comment.