Skip to content

Commit

Permalink
Merge branch 'release/1.4.30' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Apr 9, 2018
2 parents 20bd58c + 09cf32b commit 3755531
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ImageOptimize Changelog

## 1.4.30 - 2018.04.09
### Added
* Added additional profiling information

## 1.4.29 - 2018.04.06
### Added
* Added profiling to the image variant creation
Expand Down
4 changes: 2 additions & 2 deletions 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.29",
"version": "1.4.30",
"keywords": [
"craft",
"cms",
Expand All @@ -28,7 +28,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"craftcms/cms": "^3.0.0-RC12",
"craftcms/cms": "^3.0.0",
"imgix/imgix-php": "^1.1.0",
"ksubileau/color-thief-php": "^1.3",
"mikehaertl/php-shellcommand": "~1.2"
Expand Down
8 changes: 8 additions & 0 deletions src/services/Optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Optimize extends Component
*/
public function handleGetAssetUrlEvent(GetAssetUrlEvent $event)
{
Craft::beginProfile('handleGetAssetUrlEvent', __METHOD__);
$url = null;
$settings = ImageOptimize::$plugin->getSettings();
if ($settings->transformMethod != 'craft') {
Expand Down Expand Up @@ -89,6 +90,7 @@ public function handleGetAssetUrlEvent(GetAssetUrlEvent $event)
ImageOptimize::$transformParams
);
}
Craft::endProfile('handleGetAssetUrlEvent', __METHOD__);

return $url;
}
Expand All @@ -102,6 +104,7 @@ public function handleGetAssetUrlEvent(GetAssetUrlEvent $event)
*/
public function handleGenerateTransformEvent(GenerateTransformEvent $event)
{
Craft::beginProfile('handleGenerateTransformEvent', __METHOD__);
$tempPath = null;

$settings = ImageOptimize::$plugin->getSettings();
Expand Down Expand Up @@ -152,6 +155,7 @@ public function handleGenerateTransformEvent(GenerateTransformEvent $event)
$tempPath
);
}
Craft::endProfile('handleGenerateTransformEvent', __METHOD__);

return $tempPath;
}
Expand Down Expand Up @@ -200,6 +204,7 @@ public function saveTransformToTempFile(AssetTransformIndex $index, Image $image
*/
public function optimizeImage(AssetTransformIndex $index, string $tempPath)
{
Craft::beginProfile('optimizeImage', __METHOD__);
$settings = ImageOptimize::$plugin->getSettings();
// Get the active processors for the transform format
$activeImageProcessors = $settings->activeImageProcessors;
Expand All @@ -215,6 +220,7 @@ public function optimizeImage(AssetTransformIndex $index, string $tempPath)
}
}
}
Craft::endProfile('optimizeImage', __METHOD__);
}

/**
Expand Down Expand Up @@ -244,6 +250,7 @@ public function humanFileSize($bytes, $decimals = 1): string
*/
public function createImageVariants(AssetTransformIndex $index, Asset $asset, string $tempPath)
{
Craft::beginProfile('createImageVariants', __METHOD__);
$settings = ImageOptimize::$plugin->getSettings();
// Get the active image variant creators
$activeImageVariantCreators = $settings->activeImageVariantCreators;
Expand Down Expand Up @@ -304,6 +311,7 @@ public function createImageVariants(AssetTransformIndex $index, Asset $asset, st
}
}
}
Craft::endProfile('createImageVariants', __METHOD__);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/services/OptimizedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function populateOptimizedImageModel(Asset $asset, $variants, OptimizedIm
*/
protected function generatePlaceholders(Asset $element, OptimizedImage $model, $aspectRatio)
{
Craft::beginProfile('generatePlaceholders', __METHOD__);
$settings = ImageOptimize::$plugin->getSettings();
if ($settings->generatePlaceholders && ImageOptimize::$generatePlaceholders) {
$placeholder = ImageOptimize::$plugin->placeholder;
Expand All @@ -177,6 +178,7 @@ protected function generatePlaceholders(Asset $element, OptimizedImage $model, $
@unlink($tempPath);
}
}
Craft::endProfile('generatePlaceholders', __METHOD__);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/services/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function generatePlaceholderBox($width, $height, $color = null)
*/
public function generatePlaceholderImage(string $tempPath, float $aspectRatio, $position): string
{
Craft::beginProfile('generatePlaceholderImage', __METHOD__);
$result = '';
$width = self::PLACEHOLDER_WIDTH;
$height = intval($width / $aspectRatio);
Expand All @@ -88,6 +89,7 @@ public function generatePlaceholderImage(string $tempPath, float $aspectRatio, $
$result = base64_encode(file_get_contents($placeholderPath));
unlink($placeholderPath);
}
Craft::endProfile('generatePlaceholderImage', __METHOD__);

return $result;
}
Expand All @@ -101,6 +103,7 @@ public function generatePlaceholderImage(string $tempPath, float $aspectRatio, $
*/
public function generateColorPalette(string $tempPath): array
{
Craft::beginProfile('generateColorPalette', __METHOD__);
$colorPalette = [];
if (!empty($tempPath)) {
// Extract the color palette
Expand All @@ -110,6 +113,7 @@ public function generateColorPalette(string $tempPath): array
$colorPalette[] = sprintf("#%02x%02x%02x", $colors[0], $colors[1], $colors[2]);
}
}
Craft::endProfile('generateColorPalette', __METHOD__);

return $colorPalette;
}
Expand All @@ -123,6 +127,7 @@ public function generateColorPalette(string $tempPath): array
*/
public function generatePlaceholderSvg(string $tempPath): string
{
Craft::beginProfile('generatePlaceholderSvg', __METHOD__);
$result = '';

if (!empty($tempPath)) {
Expand Down Expand Up @@ -151,7 +156,7 @@ public function generatePlaceholderSvg(string $tempPath): string
}
}
}

Craft::endProfile('generatePlaceholderSvg', __METHOD__);

return $result;
}
Expand All @@ -168,9 +173,11 @@ public function generatePlaceholderSvg(string $tempPath): string
*/
public function createTempPlaceholderImage(Asset $asset, float $aspectRatio, $position): string
{
Craft::beginProfile('createTempPlaceholderImage', __METHOD__);
$width = self::TEMP_PLACEHOLDER_WIDTH;
$height = intval($width / $aspectRatio);
$tempPath = $this->createImageFromAsset($asset, $width, $height, self::TEMP_PLACEHOLDER_QUALITY, $position);
Craft::endProfile('createTempPlaceholderImage', __METHOD__);

return $tempPath;
}
Expand Down

0 comments on commit 3755531

Please sign in to comment.