Skip to content

Commit

Permalink
Merge pull request #414 from statikbe/KarelJanVanHaute/issue411
Browse files Browse the repository at this point in the history
Load original image if image optimize is not done yet
  • Loading branch information
emilyberghen authored Feb 12, 2025
2 parents b4e5c87 + ad9e4fb commit 38be22b
Show file tree
Hide file tree
Showing 16 changed files with 1,932 additions and 113 deletions.
6 changes: 3 additions & 3 deletions config/image-optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
'commandPath' => '/usr/bin/cwebp',
'commandOptions' => '-jpeg_like -af',
'commandOutputFileFlag' => '-o',
'commandQualityFlag' => '-q',
'commandQualityFlag' => '-q 100',
'imageVariantExtension' => 'webp',
],
],
Expand Down Expand Up @@ -159,10 +159,10 @@
'imageVariantCreators' => [
// webp variant creator
'cwebp' => [
'commandPath' => '/usr/local/bin/cwebp',
'commandPath' => '/usr/local/Cellar/webp/1.3.0_1/bin/cwebp',
'commandOptions' => '-jpeg_like -af',
'commandOutputFileFlag' => '-o',
'commandQualityFlag' => '-q',
'commandQualityFlag' => '-q 100',
'imageVariantExtension' => 'webp',
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ instructions: 'Optimized images for the content builder.'
name: 'Optimized Content'
searchable: false
settings:
displayDominantColorPalette: false
displayDominantColorPalette: true
displayLazyLoadPlaceholderImages: false
displayOptimizedImageVariants: false
displayOptimizedImageVariants: true
fieldVolumeSettings:
__assoc__:
-
Expand All @@ -15,6 +15,7 @@ settings:
ignoreFilesOfType:
- image/svg
- image/gif
- application/pdf
variants:
-
__assoc__:
Expand Down Expand Up @@ -112,7 +113,7 @@ settings:
- '2'
-
- quality
- '60'
- '82'
-
- format
- ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ instructions: null
name: 'Optimized Hero'
searchable: false
settings:
displayDominantColorPalette: false
displayDominantColorPalette: true
displayLazyLoadPlaceholderImages: false
displayOptimizedImageVariants: false
displayOptimizedImageVariants: true
fieldVolumeSettings:
__assoc__:
-
Expand Down Expand Up @@ -137,7 +137,7 @@ settings:
- '2'
-
- quality
- '60'
- '82'
-
- format
- ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ instructions: 'Optimized images for overview items.'
name: 'Optimized Overview'
searchable: false
settings:
displayDominantColorPalette: false
displayDominantColorPalette: true
displayLazyLoadPlaceholderImages: false
displayOptimizedImageVariants: false
displayOptimizedImageVariants: true
fieldVolumeSettings:
__assoc__:
-
Expand All @@ -15,6 +15,7 @@ settings:
ignoreFilesOfType:
- image/svg
- image/gif
- application/pdf
variants:
-
__assoc__:
Expand Down Expand Up @@ -62,7 +63,7 @@ settings:
- '2'
-
- quality
- '60'
- '82'
-
- format
- ''
Expand All @@ -87,7 +88,7 @@ settings:
- '2'
-
- quality
- '60'
- '82'
-
- format
- ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ instructions: 'Optimized images for text + image in content builder'
name: 'Optimized Text Image'
searchable: false
settings:
displayDominantColorPalette: false
displayDominantColorPalette: true
displayLazyLoadPlaceholderImages: false
displayOptimizedImageVariants: false
displayOptimizedImageVariants: true
fieldVolumeSettings:
__assoc__:
-
Expand All @@ -15,6 +15,7 @@ settings:
ignoreFilesOfType:
- image/svg
- image/gif
- application/pdf
variants:
-
__assoc__:
Expand Down Expand Up @@ -62,7 +63,7 @@ settings:
- '2'
-
- quality
- '60'
- '82'
-
- format
- ''
Expand All @@ -87,7 +88,7 @@ settings:
- '2'
-
- quality
- '60'
- '82'
-
- format
- ''
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"postcss-mixins": "^9.0.4",
"postcss-nested": "^6.0.1",
"promise-polyfill": "^8.3.0",
"tailwindcss": "^3.3.5",
"tailwindcss": "^3.4.16",
"terser": "^5.24.0",
"typescript": "5.3.2",
"vite": "^5.0.13",
Expand All @@ -51,6 +51,7 @@
"@popperjs/core": "^2.11.8",
"flatpickr": "^4.6.13",
"leaflet": "^1.9.4",
"tailwind": "^4.0.0",
"tippy.js": "^6.3.7",
"vite-plugin-dynamic-import": "^1.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
sizes="(max-width: 479px) 95vw, (min-width: 480px) and (max-width: 659px) 448px, (min-width: 660px) and (max-width: 819px) 628px, (min-width: 820px) and (max-width: 979px) 378px, (min-width: 980px) and (max-width: 1199px) 458px, (min-width: 1200px) 568px"
type="image/webp"/>
{% endif %}
<img src="{{ optimizedImage.placeholderBox() }}"
<img src="{{ optimizedImage.optimizedImageUrls|length == 0 ? image.getUrl() : optimizedImage.placeholderBox() }}"
srcset="{{ optimizedImage.srcset() }}"
sizes="(max-width: 479px) 95vw, (min-width: 480px) and (max-width: 659px) 448px, (min-width: 660px) and (max-width: 819px) 628px, (min-width: 820px) and (max-width: 979px) 378px, (min-width: 980px) and (max-width: 1199px) 458px, (min-width: 1200px) 568px"
alt="{{ image.alt }}"
Expand Down
2 changes: 1 addition & 1 deletion templates/_site/_snippet/_content/_blocks/_image.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
class="w-full {% if block.showLargerVersionInPopup %}h-full object-cover{% endif %}"
loading="lazy"/>
{% else %}
<img src="{{ optimizedImage.placeholderBox() }}"
<img src="{{ optimizedImage.optimizedImageUrls|length == 0 ? image.getUrl() : optimizedImage.placeholderBox() }}"
srcset="{{ optimizedImage.srcset() }}"
sizes="{{sizes}}"
width="{{ optimizedImage.placeholderWidth }}"
Expand Down
3 changes: 2 additions & 1 deletion templates/_site/_snippet/_content/_blocks/_slider.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
sizes="(max-width: 819px) 100vw, (min-width: 820px) 780px"
type="image/webp"/>
{% endif %}
<img src="{{ optimizedImage.placeholderBox() }}"
<img src="{{ optimizedImage.optimizedImageUrls|length == 0 ? image.getUrl() : optimizedImage.placeholderBox() }}"
srcset="{{ optimizedImage.srcset() }}"
sizes="(max-width: 819px) 100vw, (min-width: 820px) 780px"
width="{{optimizedImage.placeholderWidth}}" height="{{optimizedImage.placeholderHeight}}"
alt="{{ image.alt }}"
class="aspect-[4/3] object-cover w-full object-center"
loading="lazy"/>
</picture>
</a>
Expand Down
2 changes: 1 addition & 1 deletion templates/_site/_snippet/_content/_blocks/_textImage.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
alt="{{ image.alt }}"
class="w-full" loading="lazy"/>
{% else %}
<img src="{{ optimizedImage.placeholderBox() }}"
<img src="{{ optimizedImage.optimizedImageUrls|length == 0 ? image.getUrl() : optimizedImage.placeholderBox() }}"
srcset="{{ optimizedImage.srcset() }}"
sizes="(max-width: 479px) 95vw, (min-width: 480px) and (max-width: 659px) 448px, (min-width: 660px) and (max-width: 819px) 628px, (min-width: 820px) and (max-width: 979px) 378px, (min-width: 980px) and (max-width: 1199px) 458px, (min-width: 1200px) 568px"
width="{{optimizedImage.placeholderWidth}}" height="{{optimizedImage.placeholderHeight}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/_site/_snippet/_content/_blocks/_textVideo.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
sizes="(max-width: 479px) 100vw, (min-width: 480px) and (max-width: 659px) 448px, (min-width: 660px) and (max-width: 819px) 628px, (min-width: 820px) and (max-width: 979px) 378px, (min-width: 980px) and (max-width: 1199px) 458px, (min-width: 1200px) 568px"
type="image/webp"/>
{% endif %}
<img src="{{ optimizedImage.placeholderBox() }}"
<img src="{{ optimizedImage.optimizedImageUrls|length == 0 ? image.getUrl() : optimizedImage.placeholderBox() }}"
srcset="{{ optimizedImage.srcset() }}"
sizes="(max-width: 479px) 100vw, (min-width: 480px) and (max-width: 659px) 448px, (min-width: 660px) and (max-width: 819px) 628px, (min-width: 820px) and (max-width: 979px) 378px, (min-width: 980px) and (max-width: 1199px) 458px, (min-width: 1200px) 568px"
width="{{optimizedImage.placeholderWidth}}" height="{{optimizedImage.placeholderHeight}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/_site/_snippet/_content/_blocks/_video.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
sizes="(max-width: 479px) 100vw, (min-width: 480px) and (max-width: 659px) 448px, (min-width: 660px) and (max-width: 819px) 628px, (min-width: 820px) and (max-width: 979px) 526px, (min-width: 980px) and (max-width: 1199px) 632px, (min-width: 1200px) 779px"
type="image/webp"/>
{% endif %}
<img src="{{ optimizedImage.placeholderBox() }}"
<img src="{{ optimizedImage.optimizedImageUrls|length == 0 ? image.getUrl() : optimizedImage.placeholderBox() }}"
srcset="{{ optimizedImage.srcset() }}"
sizes="(max-width: 479px) 100vw, (min-width: 480px) and (max-width: 659px) 448px, (min-width: 660px) and (max-width: 819px) 628px, (min-width: 820px) and (max-width: 979px) 526px, (min-width: 980px) and (max-width: 1199px) 632px, (min-width: 1200px) 779px"
width="{{optimizedImage.placeholderWidth}}" height="{{optimizedImage.placeholderHeight}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/_site/_snippet/_content/_defaultHeader.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
width="{{ headerImage.width }}" height="{{ headerImage.height }}"
alt="" class="sr-only js-bg-src" loading="lazy"/>
{% else %}
<img src="{{ optimizedImage.placeholderBox() }}"
<img src="{{ optimizedImage.optimizedImageUrls|length == 0 ? headerImage.getUrl() : optimizedImage.placeholderBox() }}"
srcset="{{ optimizedImage.srcset() }}"
sizes="(max-width: 479px) 95vw, (min-width: 480px) and (max-width: 659px) 448px, (min-width: 660px) and (max-width: 819px) 628px, (min-width: 820px) and (max-width: 979px) 591px, (min-width: 980px) and (max-width: 1199px) 711px, (min-width: 1200px) 876px"
width="{{ optimizedImage.placeholderWidth }}"
Expand Down
2 changes: 1 addition & 1 deletion templates/_site/_snippet/_content/_hero.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{% if craft.imageOptimize.serverSupportsWebP() and heroImage.extension != 'svg' and heroImage.extension != 'gif' and heroImage.extension != 'webp' %}
<source srcset="{{ optimizedHero.srcsetWebP() }}" sizes="100vw" type="image/webp"/>
{% endif %}
<img src="{{ optimizedHero.placeholderBox() }}" srcset="{{ optimizedHero.srcset() }}" sizes="100vw" alt="" class="sr-only js-bg-src" loading="lazy"/>
<img src="{{ optimizedHero.optimizedImageUrls|length == 0 ? heroImage.getUrl() : optimizedHero.placeholderBox() }}" srcset="{{ optimizedHero.srcset() }}" sizes="100vw" alt="" class="sr-only js-bg-src" loading="lazy"/>
</picture>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/_site/_snippet/_item/_card.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
sizes="{{ sizes }}"
type="image/webp"/>
{% endif %}
<img src="{{ optimizedImage.placeholderBox() }}"
<img src="{{ optimizedImage.optimizedImageUrls|length == 0 ? overviewImage.getUrl() : optimizedImage.placeholderBox() }}"
srcset="{{ optimizedImage.srcset() }}"
sizes="{{ sizes }}"
width="{{ optimizedImage.placeholderWidth }}"
height="{{ optimizedImage.placeholderHeight }}"
alt=""
class="w-full {% if not showInColumns %}sr-only js-bg-src{% endif %}"
class="w-full {% if not showInColumns %}sr-only js-bg-src {% else %}aspect-[4/3] object-cover w-full object-center{% endif %}"
loading="lazy"/>
</picture>
</div>
Expand Down
Loading

0 comments on commit 38be22b

Please sign in to comment.