Skip to content

Commit

Permalink
Merge branch 'release/1.6.6' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Nov 19, 2019
2 parents f9e26dc + 729de33 commit 955bcc2
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 14 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.6.6 - 2019.11.19
### Added
* Added a Preferences item to control whether allow limiting the creation of Optimized Image Variants for images by sub-folders

## 1.6.5 - 2019.11.13
### Added
* Added the ability to choose the sub-folders in an asset volume in which Optimized Image Variants will be created
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.6.5",
"version": "1.6.6",
"keywords": [
"craft",
"cms",
Expand Down
7 changes: 7 additions & 0 deletions docs/docs/Using.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

To create responsive image variants for all of your images, create an **OptimizedImages** Field and add it to the Asset Volume field layout of the images you want optimized.

ImageOptimize will pre-generate all of the Optimized Image Variants in the Asset Volume, so that this rather intensive step is preflighted, rather than being done at runtime.

You can choose to have the Optimized Image Variants created only for specific sub-folders in an Asset Volume if you like:

![Screenshot](./resources/screenshots/image-optimize-field-volumes.png)


Think of each **Optimized Images** field as encapsulating a [srcset](https://cloudfour.com/thinks/responsive-images-101-part-4-srcset-width-descriptors/) for your images. If you need to use more than one `srcset` then you probably need more than one **Optimized Images** field.

**Transform Method** let you choose to use the built-in Craft transforms or a service like [Imgix](https://www.imgix.com/) for the responsive image variants.
Expand Down
Binary file modified docs/docs/resources/screenshots/auto-sharpen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
// Controls whether images scaled down >= 50% should be automatically sharpened
'autoSharpenScaledImages' => true,

// Whether to allow limiting the creation of Optimized Image Variants for images by sub-folders
'assetVolumeSubFolders' => true,

// The default Image Transform type classes
'defaultImageTransformTypes' => [
],
Expand Down
3 changes: 3 additions & 0 deletions src/fields/OptimizedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,16 @@ public function getSettingsHtml()
}
$aspectRatio = ['x' => 2, 'y' => 2, 'custom' => true];
$aspectRatios[] = $aspectRatio;
// Get only the user-editable settings
$settings = ImageOptimize::$plugin->getSettings();

// Render the settings template
try {
return Craft::$app->getView()->renderTemplate(
'image-optimize/_components/fields/OptimizedImages_settings',
[
'field' => $this,
'settings' => $settings,
'aspectRatios' => $aspectRatios,
'id' => $id,
'name' => $this->handle,
Expand Down
8 changes: 8 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class Settings extends Model
*/
public $autoSharpenScaledImages = true;

/**
* @var bool Whether to allow limiting the creation of Optimized Image Variants
* for images by sub-folders
*/
public $assetVolumeSubFolders = true;

/**
* @var ImageTransformInterface[] The default Image Transform type classes
*/
Expand Down Expand Up @@ -320,6 +326,7 @@ public function rules()
'lowerQualityRetinaImageVariants',
'allowUpScaledImageVariants',
'autoSharpenScaledImages',
'assetVolumeSubFolders',
],
'boolean',
],
Expand Down Expand Up @@ -362,6 +369,7 @@ public function fields()
'lowerQualityRetinaImageVariants',
'allowUpScaledImageVariants',
'autoSharpenScaledImages',
'assetVolumeSubFolders',
];

return $fields;
Expand Down
26 changes: 14 additions & 12 deletions src/templates/_components/fields/OptimizedImages_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@

<div class="field" id="{{ id }}-fields">

{% if fieldVolumes is defined and fieldVolumes | length %}
{% for fieldVolume in fieldVolumes %}
{% set val = field.fieldVolumeSettings[fieldVolume.handle] ?? '*' %}
{{ forms.checkboxSelectField({
label: "Volume: " ~ fieldVolume.name,
instructions: "Create Optimized Image Variants for images in the sub-folders:"|t('image-optimize'),
name: "fieldVolumeSettings[" ~ fieldVolume.handle ~ "]",
options: fieldVolume.subfolders,
showAllOption: true,
values: val,
}) }}
{% endfor %}
{% if settings.assetVolumeSubFolders %}
{% if fieldVolumes is defined and fieldVolumes | length %}
{% for fieldVolume in fieldVolumes %}
{% set val = field.fieldVolumeSettings[fieldVolume.handle] ?? '*' %}
{{ forms.checkboxSelectField({
label: "Volume: " ~ fieldVolume.name,
instructions: "Create Optimized Image Variants for images in the sub-folders:"|t('image-optimize'),
name: "fieldVolumeSettings[" ~ fieldVolume.handle ~ "]",
options: fieldVolume.subfolders,
showAllOption: true,
values: val,
}) }}
{% endfor %}
{% endif %}
{% endif %}

{{ forms.checkboxSelectField({
Expand Down
10 changes: 9 additions & 1 deletion src/templates/settings/_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@
'on': settings.autoSharpenScaledImages,
'warning': configWarning('autoSharpenScaledImages', 'image-optimize')
}) }}

<!-- assetVolumeSubFolders -->
{{ forms.lightswitchField({
label: "Limit by Sub-Folder"|t('image-optimize'),
instructions: "Whether to allow limiting the creation of Optimized Image Variants for images by sub-folders."|t('image-optimize'),
'id': 'assetVolumeSubFolders',
'name': 'assetVolumeSubFolders',
'on': settings.assetVolumeSubFolders,
'warning': configWarning('assetVolumeSubFolders', 'image-optimize')
}) }}
</div>

{% js %}
Expand Down

0 comments on commit 955bcc2

Please sign in to comment.