tito10047 / progressive-image-bundle
High-performance progressive image loading bundle for Symfony with Blurhash placeholders, zero CLS, and smart responsive strategies.
Installs: 72
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tito10047/progressive-image-bundle
Requires
- php: >=8.2
- kornrunner/blurhash: ^1.2
- symfony/asset: ^7.4
- symfony/framework-bundle: ^6.4|^7.4|^6.4|^7.4|^8.0
- symfony/stimulus-bundle: ^2.31
- symfony/translation: ^6.4|^7.4|^8.0
- symfony/twig-bundle: ^7.4
- symfony/ux-twig-component: ^2.31
- symfony/web-link: ^6.4|^7.4|^8.0
Requires (Dev)
- ext-imagick: *
- friendsofphp/php-cs-fixer: ^3.92
- liip/imagine-bundle: ^2.16
- phpstan/phpstan: ^2.1
- phpstan/phpstan-symfony: ^2.0
- symfony/asset-mapper: ^6.4|^7.4|^8.0
- symfony/dotenv: ^7.4
- symfony/test-pack: ^1.2
- symfony/yaml: ^7.4
README
High-performance, Zero-config, Fully Responsive Images for Symfony.
This bundle handles everything you need for modern image management. From fully responsive images with Tailwind-like selectors, to blur placeholders, to * automatic generation of all required sizes* on local or network storage.
β¨ Key Features
- π Zero Configuration: Install and use. Most features work out of the box.
- π¨ Blur & Error Placeholders: Users see a beautiful Blurhash placeholder while loading. If an image is not found, the bundle automatically displays a stylish error placeholder.
- π± Tailwind-like Selectors: Define responsiveness naturally directly in your template using familiar breakpoints.
- βοΈ Automatic Generation: The bundle automatically generates all necessary image sizes on disk (local or network), saving time and resources.
- π― Zero CLS (Cumulative Layout Shift): Automatically reserves space for the image, preventing content jumping during load.
- β‘ Smart Preload: Automatically injects
<link rel="preload">for critical images (hero images), significantly improving LCP scores.
π¨ Usage
Simply use the Twig component. The bundle takes care of everything β it automatically calculates the required image dimensions for each breakpoint, resizes the original, and generates all necessary variants on the fly.
{# Basic usage - everything is automatic #} <twig:pgi:Image src="images/hero.jpg" alt="Beautiful landscape" /> {# With Tailwind-like selectors for perfect responsiveness #} <twig:pgi:Image src="images/hero.jpg" sizes="sm:12 md:6@landscape lg:4@square" alt="Responsive image" />
π± Selector Examples (Breakpoint Assignment)
The bundle supports flexible size assignment based on breakpoints you know from Tailwind or Bootstrap. For each selector, it automatically calculates the final pixel dimensions based on the container width defined by your CSS framework (Bootstrap or Tailwind) and generates the corresponding image.
| Selector | Meaning | Resulting behavior |
|---|---|---|
6 |
6 grid columns on all breakpoints | Width: 50% of container, original aspect ratio |
md:6 |
6 grid columns from md breakpoint |
From md up: 50% of container, below md: full width |
lg:4@landscape |
4 columns from lg with 16:9 aspect ratio |
From lg up: 33.3% of container, cropped to 16:9 ratio |
xs:12@square |
12 columns on xs with 1:1 aspect ratio |
Full width container, cropped to 1:1 square |
xxl:[430x370] |
Explicit dimensions for a specific breakpoint | Exact size 430x370px on xxl and larger |
xl:[100%]@landscape |
100% container width with landscape aspect ratio | Full width container, cropped to 16:9 ratio |
What is a "container"? The bundle automatically detects your CSS framework (Bootstrap or Tailwind) and extracts the exact container widths for each breakpoint from its configuration. It then uses these values to calculate the precise pixel dimensions for your images.
π Advanced Features
Point of Interest (PoI) Cropping
Define a focal point (e.g., 75x25) so the most important object remains in frame regardless of the crop.
Smart Upscaling Protection
The bundle never generates an image larger than the original. If you need 1200px but the original is only 1000px, the bundle uses the original and prevents blurring.
Stream-based Metadata
To retrieve dimensions and Blurhash, the bundle doesn't load the entire image into RAM (no 20MB files in memory). It uses PHP streams to read only the necessary header bytes.
π¦ Installation
composer require tito10047/progressive-image-bundle
βοΈ Optional Configuration
# config/packages/progressive_image.yaml progressive_image: responsive_strategy: grid: framework: tailwind # or bootstrap ratios: landscape: "16/9" portrait: "3/4" square: "1/1" image_cache_enabled: true
π License
MIT License. See LICENSE for more information.
π Documentation
For detailed guides, configuration, and advanced features, check out our full documentation: