Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Statamic Responsive Images Laravel Package

spatie/statamic-responsive-images

Statamic addon by Spatie that adds a responsive image fieldtype with art direction and breakpoint support. Automatically generates responsive variants on asset upload and renders them in Antlers via the responsive tag, with configurable breakpoints and options.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Statamic CMS Alignment: The package is tightly integrated with Statamic’s architecture, leveraging its asset system, Glide for image manipulation, and Antlers/Twig templating. This ensures seamless compatibility with Statamic’s core workflows (e.g., asset containers, fieldtypes, and entry management).
  • Responsive Image Paradigm: Adopts a modern, art-direction-first approach (e.g., ratio, src overrides, and breakpoint-based customization), aligning with performance best practices (e.g., srcset, sizes attributes, and format negotiation).
  • Extensibility: Supports customization via config files (e.g., breakpoints, quality settings, excluded containers) and view publishing, allowing TPMs to adapt the package to specific design systems or performance requirements.

Integration Feasibility

  • Low Friction: Installation is Composer-based with minimal setup (single composer require command). The fieldtype integrates directly into Statamic’s UI, reducing developer overhead.
  • Glide Dependency: Relies on Statamic’s built-in Glide integration, eliminating the need for additional infrastructure (e.g., no separate image processing services required).
  • Queue Support: Image generation can be queued (default: default queue), enabling async processing for large media libraries. Configurable via responsive-images.php.
  • GraphQL Readiness: Provides GraphQL fields for headless/decoupled setups, expanding use cases beyond traditional Statamic templates.

Technical Risk

  • Performance Trade-offs:
    • Lazy Generation: Recommends disabling statamic.assets.image_manipulation.cache to generate images on-demand, which may impact initial load times for high-traffic sites. Mitigation: Use CDN caching or pre-generate critical images via the regenerate command.
    • Storage Overhead: Generates multiple variants (original + WEBP/AVIF) by default. Risk: Increased storage costs. Mitigation: Configure webp/avif settings globally or per-tag.
  • Breakpoint Management:
    • Defaults to Tailwind CSS breakpoints, which may not align with all design systems. Customization requires config file updates or runtime overrides (e.g., lg:ratio="16/9").
  • Statamic Version Lock:
    • Statamic 4.0+ required (explicitly stated). Compatibility with Statamic 6.x is confirmed (changelog), but backward compatibility with older versions is untested. Risk: Potential deprecation issues if Statamic evolves its asset API.
  • Edge Cases:
    • Asset Reference Updates: Fixed in v6.2.0 for Statamic 6.6+, but migration paths for older versions may require manual testing.
    • Placeholder Generation: Moved to a job queue in v5.2.1, reducing server load but introducing race conditions if not properly configured.

Key Questions for TPM

  1. Performance vs. Storage:
    • Should we pre-generate all variants (for predictable performance) or lazy-generate (to save storage)?
    • How will we handle CDN caching for dynamically generated images?
  2. Breakpoint Strategy:
    • Do our design systems align with Tailwind’s breakpoints, or should we customize them in responsive-images.php?
  3. Format Support:
    • Should we enable AVIF (better compression) despite broader browser support risks, or stick to WEBP?
  4. Queue Configuration:
    • Is the default queue sufficient, or should we dedicate a queue (e.g., images) for image processing?
  5. Fallbacks:
    • How should we handle unsupported browsers (e.g., no srcset support)? Use polyfills or static fallbacks?
  6. Monitoring:
    • What metrics (e.g., image generation time, storage growth) should we track to ensure scalability?

Integration Approach

Stack Fit

  • Statamic Ecosystem:
    • Core Integration: Works natively with Statamic’s asset containers, fieldtypes, and Glide pipeline. No middleware or custom routes required.
    • Templating: Supports Antlers (legacy) and Twig (Statamic 4+), with GraphQL for headless use cases.
    • Fieldtype UI: Provides a dedicated fieldtype for art direction, reducing reliance on custom code for responsive images.
  • Laravel Compatibility:
    • Laravel 12.x Support: Confirmed in v6.0.0, ensuring alignment with Statamic’s underlying framework.
    • Queue System: Leverages Laravel’s queue workers for async image processing (e.g., Horizon, Supervisor).

Migration Path

  1. Assessment Phase:
    • Audit existing image fields (e.g., assets, upload) to identify high-impact use cases (e.g., hero banners, product galleries).
    • Review current Glide presets to determine if they conflict with the package’s auto-generated variants.
  2. Pilot Implementation:
    • Install the package in a staging environment and test with a subset of entries.
    • Validate breakpoint behavior and format generation (e.g., WEBP fallbacks).
  3. Phased Rollout:
    • Phase 1: Replace static img tags with {{ responsive:field }} in templates.
    • Phase 2: Migrate custom image logic (e.g., PHP-based resizing) to use the fieldtype’s art direction.
    • Phase 3: Update GraphQL schemas (if applicable) to include responsive fields.
  4. Deprecation:
    • Phase out legacy image fields (e.g., assets without use_breakpoints) in favor of the responsive fieldtype.

Compatibility

  • Statamic Versions:
    • Tested: Statamic 4.0–6.x (changelog confirms 6.x support).
    • Untested: Statamic 3.x (not supported per README).
  • Glide Dependencies:
    • Requires Statamic’s Glide integration. No conflicts if using default Glide config.
    • Custom Glide filters (e.g., blur, fit) can be passed via glide:param syntax.
  • Third-Party Addons:
    • Potential Conflicts: Addons modifying asset events (e.g., asset.saving) may interfere with image generation jobs. Mitigation: Test in isolation or coordinate with addon authors.
    • Bard/Replicator: Fixed in v2.5.3 for nested fieldtype usage.

Sequencing

  1. Pre-requisites:
    • Ensure statamic/glide is installed (included by default in Statamic 4+).
    • Configure queue workers if using async processing (e.g., php artisan queue:work).
  2. Installation:
    composer require spatie/statamic-responsive-images
    php artisan vendor:publish --provider="Spatie\ResponsiveImages\ServiceProvider"  # Optional: Customize views
    
  3. Configuration:
    • Update config/responsive-images.php for breakpoints, format preferences, and excluded containers.
    • Set statamic.assets.image_manipulation.cache to false (recommended for lazy generation).
  4. Fieldtype Migration:
    • Replace existing assets fields with the responsive fieldtype in blueprints.
    • Example:
      type: responsive
      use_breakpoints: true
      breakpoints: [sm, md, lg, xl]
      
  5. Template Updates:
    • Replace {{ asset:field }} with {{ responsive:field }} in Twig/Antlers.
    • Example with art direction:
      {{ responsive:hero_image ratio="16/9" lg:ratio="2/1" }}
      
  6. Testing:
    • Verify responsive behavior across devices (e.g., Chrome DevTools).
    • Test edge cases (e.g., missing assets, unsupported formats).
  7. Optimization:
    • Monitor image generation times and adjust queue settings if needed.
    • Implement CDN caching for dynamic variants (e.g., Cloudflare, Fastly).

Operational Impact

Maintenance

  • Configuration-Driven:
    • Most settings are centralized in responsive-images.php, reducing scattered logic across templates.
    • Breakpoints, quality settings, and format preferences can be updated globally.
  • Dependency Updates:
    • Automated: Composer handles updates, but Statamic version compatibility must be validated (e.g., test after Statamic minor updates).
    • Critical Path: Glide and Statamic asset API changes may require package updates (e
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai