nx6 / fastly-cms-images
Magento 2 add-on for Fastly_Cdn that runs CMS/WYSIWYG images through Fastly image optimization and keeps PLP thumbnails at their native aspect ratio.
Package info
github.com/tinchodev/magento2-fastly-cdn-cms-images
Type:magento2-module
pkg:composer/nx6/fastly-cms-images
Requires
- php: ^8.3
- fastly/magento2: >=1.2
- magento/framework: >=103.0
- magento/module-catalog: >=104.0
- magento/module-widget: >=101.3
README
Small integration fixes on top of the official
Fastly_Cdn module, covering
CMS image optimization and PLP thumbnail handling. It never talks to
Fastly directly — it plugs into Fastly_Cdn and Magento_Widget to adjust the
image URLs Fastly ends up serving.
| Package | nx6/fastly-cms-images |
| Module | Nx6_Fastly |
| Version | 1.0.0 |
Why
Fastly_Cdn's image optimization only rewrites catalog images. Images dropped
into CMS blocks / pages through the WYSIWYG editor ({{media url="..."}}) are
served untouched, and PLP thumbnails get letterboxed to the category image
canvas. This module closes both gaps with two thin plugins — no core overrides,
no template changes.
Installation
composer require nx6/fastly-cms-images
bin/magento module:enable Nx6_Fastly
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
Requires the Fastly_Cdn extension (fastly/magento2) to be installed and its
image optimization feature enabled.
What it does
CMS image optimization params — Plugin/Template/FilterPlugin.php
Plugs into Magento\Widget\Model\Template\Filter::mediaDirective (the
{{media url="..."}} directive used in CMS content). When
Fastly\Cdn\Model\Config::isImageOptimizationEnabled() is on, it appends
Fastly image-optimization query params — format=jpeg&auto=webp&fit=bounds&bg-color=FFF
— to the resulting URL for jpg / jpeg / png images. Fastly then serves
auto-converted, right-sized images for CMS content without editing the CMS markup.
PLP thumbnail aspect ratio — Plugin/Model/View/Asset/ImagePlugin.php
Plugs into Fastly\Cdn\Model\View\Asset\Image::getUrl. For image URLs matching
the PLP thumbnail canvas size (240:300), it strips the &fit=bounds parameter
so those thumbnails keep their original aspect ratio instead of being
letterboxed to fit the canvas.
Compatibility
Magento 2.4.x, PHP 8.3+, Fastly_Cdn 1.2+.
Structure
.
├── Plugin/
│ ├── Model/View/Asset/ImagePlugin.php # PLP thumbnail aspect-ratio fix
│ └── Template/FilterPlugin.php # CMS image optimization params
├── etc/
│ ├── frontend/di.xml # Registers FilterPlugin
│ └── module.xml
├── registration.php
├── composer.json
├── LICENSE
└── README.md
License
MIT — see LICENSE.