Skip to content

Commit

Permalink
Merge branch 'release/1.4.29' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Apr 7, 2018
2 parents 88d3268 + 56350ea commit 20bd58c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

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.28",
"version": "1.4.29",
"keywords": [
"craft",
"cms",
Expand Down
2 changes: 1 addition & 1 deletion src/services/Optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions src/services/OptimizedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -60,6 +61,7 @@ public function createOptimizedImages(Asset $asset, $variants = [])

$model = new OptimizedImage();
$this->populateOptimizedImageModel($asset, $variants, $model);
Craft::endProfile('createOptimizedImages', __METHOD__);

return $model;
}
Expand All @@ -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 = [];
Expand Down Expand Up @@ -137,6 +140,7 @@ public function populateOptimizedImageModel(Asset $asset, $variants, OptimizedIm
);
}
}
Craft::endProfile('populateOptimizedImageModel', __METHOD__);
}

// Protected Methods
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -253,6 +258,7 @@ protected function addVariantImageToModel(Asset $asset, OptimizedImage $model, $
__METHOD__
);
}
Craft::endProfile('addVariantImageToModel', __METHOD__);
}

/**
Expand Down

0 comments on commit 20bd58c

Please sign in to comment.