mehdismekouar/laravel-glide-helper

A Laravel helper for image manipulation using Spatie Glide

Fund package maintenance!
mehdismekouar

Installs: 2

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/mehdismekouar/laravel-glide-helper

v1.0.0 2025-10-20 12:04 UTC

This package is auto-updated.

Last update: 2025-10-20 14:22:30 UTC


README

Latest Version on Packagist Total Downloads

A simple Laravel helper function for on-the-fly image manipulation using Spatie Glide.

Features

  • 🚀 On-the-fly image manipulation - Resize, crop, and transform images dynamically
  • 💾 Automatic caching - Generated images are cached to avoid regeneration
  • 🔧 Configurable defaults - Set global parameters for consistent image processing
  • 📁 Multiple source support - Works with storage/ and public/ directories
  • 🌐 External URL handling - Passes through external URLs unchanged
  • Performance optimized - Only processes when necessary

Installation

Install the package via Composer:

composer require mehdismekouar/laravel-glide-helper

Optionally, publish the config file:

php artisan vendor:publish --tag="laravel-glide-helper-config"

This is the contents of the published config file:

return [
    'defaults' => [
        'q' => 90,          // Quality (1-100)
        'fm' => 'webp',     // Format (webp, jpg, png, gif)
        'fit' => 'max'      // Fit (contain, max, fill, stretch, crop)
    ],
    'output_dir' => 'manipulated', // Directory for cached images
];

Usage

Basic Usage

// In Blade templates
<img src="{{ glide('/storage/photos/image.jpg', ['w' => 300, 'h' => 200]) }}" alt="Resized">

Common Parameters

// Resize
glide($image, ['w' => 300, 'h' => 200])

// Crop to exact dimensions
glide($image, ['w' => 200, 'h' => 200, 'fit' => 'crop'])

// Change format and quality
glide($image, ['fm' => 'webp', 'q' => 85])

// Apply filters
glide($image, ['filt' => 'greyscale', 'blur' => 5])

Supported Parameters

All Glide parameters are supported:

  • Size: w (width), h (height), fit (contain, max, fill, stretch, crop)
  • Format: fm (webp, jpg, png, gif), q (quality 1-100)
  • Effects: blur, sharp, filt (greyscale)

How It Works

  1. Path Resolution: Automatically detects if image is in storage/ or public/
  2. Caching: Creates a unique hash based on source file and parameters
  3. Generation: Uses Spatie Glide to manipulate image only if not cached
  4. URL Generation: Returns asset URL for the manipulated image

External URLs are passed through unchanged.

Requirements

  • PHP 8.1+
  • Laravel 10+
  • spatie/laravel-glide package (automatically installed)

Credits

License

The MIT License (MIT). Please see License File for more information.