From 75c5e92ff84571180d73290971edd14fbcb19173 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 6 Apr 2018 21:44:57 -0400 Subject: [PATCH 1/3] Version 1.4.29 Signed-off-by: Andrew Welch --- CHANGELOG.md | 8 ++++++++ composer.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aa3eecd..5e3770ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # ImageOptimize Changelog +## 1.4.29 - 2018.04.06 +### Added +* Added profiling to the image variant creation + +### Changed +* Vastly increase the speed with which the transforms are created when done via Twig templating code +* Increased the speed of the variant creation in general + ## 1.4.28 - 2018.04.02 ### Changed * Switched over to using the Unsharp Mask (`usm`) filter for auto-sharpening Imgix images diff --git a/composer.json b/composer.json index a5d201a2..036c3cce 100644 --- a/composer.json +++ b/composer.json @@ -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.28", + "version": "1.4.29", "keywords": [ "craft", "cms", From 622df2f2f8bd16a8dd18b246f642c17245236222 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 6 Apr 2018 21:45:04 -0400 Subject: [PATCH 2/3] Updated README.md Signed-off-by: Andrew Welch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e179e317..43aadd80 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ If you plan to do this manually via the above console commands, you can disable If you wish to dynamically create Optimized Image Variants in your templates without having to use the Field. -**N.B.:** We recommend _against_ using Image Optimize via Twig. If you create the Optimized Image Variants in your templates, the image transforms, placeholder images, and color palette extraction will all be done at pageload time. This means you'll miss out on the advantages of using the OptimizedImages field, where all of that computation is done when an Asset is saved. +**N.B.:** We recommend _against_ using Image Optimize via Twig if you can avoid it. If you create the Optimized Image Variants in your templates, the image transforms, placeholder images, and color palette extraction will all be done at pageload time. This means you'll miss out on the advantages of using the OptimizedImages field, where all of that computation is done when an Asset is saved. To create Optimized Image Variants dynamically in your templates, you can do: From 56350ea61dad8ae69e35c03bdd91306e7aadaf3a Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 6 Apr 2018 21:46:04 -0400 Subject: [PATCH 3/3] Vastly increase the speed with which the transforms are created when done via Twig templating code Signed-off-by: Andrew Welch --- src/services/Optimize.php | 2 +- src/services/OptimizedImages.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/services/Optimize.php b/src/services/Optimize.php index 02d2471d..e4ff8c07 100644 --- a/src/services/Optimize.php +++ b/src/services/Optimize.php @@ -106,7 +106,7 @@ public function handleGenerateTransformEvent(GenerateTransformEvent $event) $settings = ImageOptimize::$plugin->getSettings(); // Only do this for local Craft transforms - if ($settings->transformMethod == 'craft' && !empty($event->asset) && ImageOptimize::$generatePlaceholders) { + if ($settings->transformMethod == 'craft' && !empty($event->asset)) { // Apply any filters to the image if (!empty($event->transformIndex->transform)) { $this->applyFiltersToImage($event->transformIndex->transform, $event->asset, $event->image); diff --git a/src/services/OptimizedImages.php b/src/services/OptimizedImages.php index d4cda773..a9a658e8 100644 --- a/src/services/OptimizedImages.php +++ b/src/services/OptimizedImages.php @@ -51,6 +51,7 @@ class OptimizedImages extends Component */ public function createOptimizedImages(Asset $asset, $variants = []) { + Craft::beginProfile('createOptimizedImages', __METHOD__); if (empty($variants)) { $settings = ImageOptimize::$plugin->getSettings(); if ($settings) { @@ -60,6 +61,7 @@ public function createOptimizedImages(Asset $asset, $variants = []) $model = new OptimizedImage(); $this->populateOptimizedImageModel($asset, $variants, $model); + Craft::endProfile('createOptimizedImages', __METHOD__); return $model; } @@ -71,6 +73,7 @@ public function createOptimizedImages(Asset $asset, $variants = []) */ public function populateOptimizedImageModel(Asset $asset, $variants, OptimizedImage $model) { + Craft::beginProfile('populateOptimizedImageModel', __METHOD__); $settings = ImageOptimize::$plugin->getSettings(); // Empty our the optimized image URLs $model->optimizedImageUrls = []; @@ -137,6 +140,7 @@ public function populateOptimizedImageModel(Asset $asset, $variants, OptimizedIm ); } } + Craft::endProfile('populateOptimizedImageModel', __METHOD__); } // Protected Methods @@ -219,6 +223,7 @@ protected function getTransformFromVariant(Asset $asset, $variant, $retinaSize): */ protected function addVariantImageToModel(Asset $asset, OptimizedImage $model, $transform, $variant, $aspectRatio) { + Craft::beginProfile('addVariantImageToModel', __METHOD__); // Generate an image transform url $url = ImageOptimize::$transformClass::getTransformUrl( $asset, @@ -233,11 +238,11 @@ protected function addVariantImageToModel(Asset $asset, OptimizedImage $model, $ if (!empty($url)) { $model->variantSourceWidths[] = $variant['width']; // Store & prefetch image at the image URL - ImageOptimize::$transformClass::prefetchRemoteFile($url); + //ImageOptimize::$transformClass::prefetchRemoteFile($url); $model->optimizedImageUrls[$transform->width] = $url; // Store & prefetch image at the webp URL $webPUrl = ImageOptimize::$transformClass::getWebPUrl($url); - ImageOptimize::$transformClass::prefetchRemoteFile($webPUrl); + //ImageOptimize::$transformClass::prefetchRemoteFile($webPUrl); $model->optimizedWebPImageUrls[$transform->width] = $webPUrl; $model->focalPoint = $asset->focalPoint; $model->originalImageWidth = $asset->width; @@ -253,6 +258,7 @@ protected function addVariantImageToModel(Asset $asset, OptimizedImage $model, $ __METHOD__ ); } + Craft::endProfile('addVariantImageToModel', __METHOD__); } /**