PHPackages                             maccesar/laravel-glide-enhanced - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. maccesar/laravel-glide-enhanced

ActiveLibrary[Image &amp; Media](/categories/media)

maccesar/laravel-glide-enhanced
===============================

Enhanced dynamic image processing for Laravel using Glide

v2.1.0(9mo ago)026MITPHPPHP ^8.0

Since Apr 7Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/macCesar/laravel-glide-enhanced)[ Packagist](https://packagist.org/packages/maccesar/laravel-glide-enhanced)[ RSS](/packages/maccesar-laravel-glide-enhanced/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (13)Used By (0)

Laravel Glide Enhanced
======================

[](#laravel-glide-enhanced)

A Laravel package for dynamic image processing based on [Spatie/Laravel-Glide](https://github.com/spatie/laravel-glide).

⚠️ Important Update (v2.x)
--------------------------

[](#️-important-update-v2x)

The default route prefix has changed from `/img/` to `/glide/` to avoid conflicts with other packages, especially `laravel-dropzone-enhanced`.

**Before:** `https://your-site.com/img/path/image.jpg`
**Now:** `https://your-site.com/glide/path/image.jpg`

See the [UPGRADE.md](UPGRADE.md) file for migration instructions.

Features
--------

[](#features)

- Dynamic image processing (resizing, cropping, format conversion)
- Image optimization for web use
- Automatic caching for improved performance
- Configurable default images by category
- Predefined presets for consistent image usage
- `HasImages` trait for Eloquent models
- `ImageProcessor` facade for easy access
- Configurable routes to avoid conflicts with other packages
- **Full compatibility with Laravel Dropzone Enhanced**

Current Limitations
-------------------

[](#current-limitations)

- The package currently works only with local files (using the 'local' and 'public' disks)
- External storage services like AWS S3 are not fully supported for image processing
- URLs from external services are recognized but cannot be dynamically processed

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require maccesar/laravel-glide-enhanced
```

The package will automatically register its service provider and facade.

Then publish the configuration file:

```
php artisan vendor:publish --tag=images-config
```

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Laravel 8.x, 9.x, 10.x, 11.x, or 12.x
- [Spatie's Laravel Glide package](https://github.com/spatie/laravel-glide)

Configuration
-------------

[](#configuration)

The `config/images.php` file contains several configuration options:

```
return [
    // Image cache configuration
    'cache' => [
        'lifetime' => 30, // days
        'path' => 'cache/glide',
    ],

    // Default processing settings
    'defaults' => [
        'fit' => 'max',     // Default fit mode (max, crop, fill, stretch)
        'quality' => 85,    // Default quality (0-100)
        'format' => 'webp', // Default output format (webp, jpg, png, etc.)
    ],

    // Routes configuration
    'routes' => [
        'enabled' => true,       // Enable/disable package routes
        'prefix' => 'glide',     // URL prefix for the image routes
        'middleware' => ['web'],  // Middleware to apply to the routes
    ],

    // Disk configuration. Change to 'local' if your images are in /storage/app
    'disk' => 'public',

    // Default fallback images by category
    'fallback_images' => [
        'default' => 'defaults/no-image.jpg',
        'documents' => 'defaults/document.jpg',
        'evidence' => 'defaults/evidence.jpg',
        'products' => 'defaults/product.jpg',
        'users' => 'defaults/user.jpg',
    ],

    // Predefined presets for image conversion
    'presets' => [
        'large' => ['dimensions' => '800', 'format' => 'webp', 'fit' => 'max'],
        'medium' => ['dimensions' => '400', 'format' => 'webp', 'fit' => 'max'],
        'social' => ['dimensions' => '1200x630', 'format' => 'jpg', 'fit' => 'crop'],
        'thumbnail' => ['dimensions' => '150x150', 'format' => 'webp', 'fit' => 'crop'],
    ],
];
```

### Disk Configuration

[](#disk-configuration)

The `disk` configuration allows you to specify where your images are stored. By default, the package uses the `public` disk, which corresponds to the `/storage/app/public` directory. If your images are stored in a different location, such as the root of `/storage/app`, you can change the disk to `local` or any other disk defined in your Laravel filesystem configuration.

```
'disk' => 'public', // Change to 'local' if your images are in /storage/app
```

For example, if your images are stored in `/storage/app`, update the configuration as follows:

```
'disk' => 'local',
```

Make sure the disk you specify is properly configured in your `config/filesystems.php` file.

### Route Configuration

[](#route-configuration)

The routes section allows you to customize how the package registers its routes:

```
'routes' => [
    'enabled' => true,        // Set to false to disable all package routes
    'prefix' => 'glide',      // Change the URL prefix (e.g., 'images', 'media', etc.)
    'middleware' => ['web'],  // Add or modify middleware applied to the routes
],
```

If you need to avoid conflicts with other packages, you can change the route prefix or disable the routes entirely and implement your own.

Basic Usage
-----------

[](#basic-usage)

### Facades Available

[](#facades-available)

The package provides two facades for your convenience:

```
// Option 1: Full facade name
use MacCesar\LaravelGlideEnhanced\Facades\ImageProcessor;

// Option 2: Short alias (recommended for cleaner code)
use MacCesar\LaravelGlideEnhanced\Facades\Img;
```

Both facades provide identical functionality. We recommend using `Img` for cleaner, more readable code.

### Image Processing URLs

[](#image-processing-urls)

```
use MacCesar\LaravelGlideEnhanced\Facades\Img;

// Basic URL with parameters
Img::url('path/to/image.jpg', ['w' => 300, 'h' => 200, 'fit' => 'crop']);

// WebP optimized URL
Img::webpUrl('path/to/image.jpg', ['w' => 300, 'h' => 200, 'fit' => 'crop', 'q' => 90]);

// Use a predefined preset
Img::preset('path/to/image.jpg', 'thumbnail');
```

### HasImages Trait for Eloquent Models

[](#hasimages-trait-for-eloquent-models)

```
use MacCesar\LaravelGlideEnhanced\Traits\HasImages;

class Product extends Model
{
    use HasImages;

    // ...
}

// Usage in code
$product->getImageWebpUrl('main');
$product->getImageUrl('main', '300x200', 'webp');
$product->getImagePreset('main', 'thumbnail');
```

HasImages Trait Reference
-------------------------

[](#hasimages-trait-reference)

The `HasImages` trait provides comprehensive image processing methods for Eloquent models. Add this trait to any model that needs dynamic image processing capabilities.

### Setup

[](#setup)

```
use MacCesar\LaravelGlideEnhanced\Traits\HasImages;

class Product extends Model
{
    use HasImages;

    // Your model code...
}
```

### Available Methods

[](#available-methods)

MethodParametersReturn TypeDescription`getImageUrl($type, $dimensions, $format, $watermark, $extraParams)``string $type = 'default'`, `string $dimensions = null`, `string $format = 'pjpg'`, `string $watermark = null`, `array $extraParams = []``string`Generate image URL with custom parameters`getImageWebpUrl($type, $params)``string $type = 'default'`, `array $params = []``string`Generate WebP optimized image URL`getImagePreset($type, $preset)``string $type = 'default'`, `string $preset = 'thumbnail'``string`Generate image URL using predefined preset### Method Details

[](#method-details)

#### `getImageUrl($type = 'default', $dimensions = null, $format = 'pjpg', $watermark = null, $extraParams = [])`

[](#getimageurltype--default-dimensions--null-format--pjpg-watermark--null-extraparams--)

Generate a custom image URL with specific parameters.

**Parameters:**

- `$type` (string): Image type identifier (default, main, thumbnail, etc.)
- `$dimensions` (string|null): Format: '300' or '300x200' (width x height)
- `$format` (string): Output format (jpg, png, webp, pjpg)
- `$watermark` (string|null): Watermark to apply
- `$extraParams` (array): Additional parameters for Glide

**Example:**

```
$product = Product::find(1);

// Custom resize with crop
$imageUrl = $product->getImageUrl('main', '400x300', 'webp', null, [
    'fit' => 'crop',
    'q' => 90
]);

// With watermark and effects
$imageUrl = $product->getImageUrl('main', '600', 'jpg', 'watermarks/logo.png', [
    'blur' => 5,
    'bright' => 10,
    'markpos' => 'bottom-right'
]);

// Just width, no processing
$imageUrl = $product->getImageUrl('main'); // Returns original URL
```

#### `getImageWebpUrl($type = 'default', array $params = [])`

[](#getimagewebpurltype--default-array-params--)

Generate a WebP optimized image URL using the ImageProcessor facade.

**Parameters:**

- `$type` (string): Image type identifier (default, main, thumbnail, etc.)
- `$params` (array): Glide parameters for image processing

**Example:**

```
$product = Product::find(1);

// Simple WebP with default settings
$webpUrl = $product->getImageWebpUrl('main');

// WebP with custom parameters
$webpUrl = $product->getImageWebpUrl('main', [
    'w' => 600,
    'fit' => 'crop',
    'q' => 95
]);
```

#### `getImagePreset($type = 'default', $preset = 'thumbnail')`

[](#getimagepresettype--default-preset--thumbnail)

Generate image URL using a predefined preset configuration.

**Parameters:**

- `$type` (string): Image type identifier (default, main, thumbnail, etc.)
- `$preset` (string): Preset name (thumbnail, medium, large, social)

**Example:**

```
$product = Product::find(1);

$thumbnail = $product->getImagePreset('main', 'thumbnail'); // 150x150 WebP cropped
$medium = $product->getImagePreset('main', 'medium');       // 400px WebP
$large = $product->getImagePreset('main', 'large');         // 800px WebP
$social = $product->getImagePreset('main', 'social');       // 1200x630 JPG for social sharing
```

### Image Path Resolution

[](#image-path-resolution)

The trait automatically resolves image paths using these strategies:

1. **Custom methods**: `get{Type}ImagePath()` method in your model
2. **Model properties**: Direct property access (`$this->{$type}`)
3. **Backward compatibility**: For 'default' type, checks `image`, `imagen`, or `foto` properties

**Example:**

```
class Product extends Model
{
    use HasImages;

    // Method 1: Custom method for specific type
    public function getMainImagePath()
    {
        return $this->main_photo;
    }

    // Method 2: Direct property access
    // $product->gallery_1, $product->featured, etc.
}

// Usage
$product->getImageUrl('main');      // Uses getMainImagePath()
$product->getImageUrl('gallery_1'); // Uses $product->gallery_1 property
$product->getImageUrl('default');   // Uses $product->image property
```

Image Presets
-------------

[](#image-presets)

Laravel Glide Enhanced includes predefined presets for common image sizes and formats. These presets ensure consistent image processing across your application.

### Available Presets

[](#available-presets)

PresetDimensionsFormatFit ModeQualityBest Used For`thumbnail`150x150WebPcrop85Avatar images, small previews, gallery thumbnails`medium`400px widthWebPmax85Card images, product listings, blog post previews`large`800px widthWebPmax85Featured images, hero sections, detailed views`social`1200x630JPGcrop85Social media sharing (Open Graph, Twitter Cards)### Preset Configuration

[](#preset-configuration)

The presets are defined in your `config/images.php` file:

```
'presets' => [
    'thumbnail' => [
        'dimensions' => '150x150',
        'format' => 'webp',
        'fit' => 'crop'
    ],
    'medium' => [
        'dimensions' => '400',
        'format' => 'webp',
        'fit' => 'max'
    ],
    'large' => [
        'dimensions' => '800',
        'format' => 'webp',
        'fit' => 'max'
    ],
    'social' => [
        'dimensions' => '1200x630',
        'format' => 'jpg',
        'fit' => 'crop'
    ],
],
```

### Custom Presets

[](#custom-presets)

You can create your own presets by adding them to the configuration:

```
'presets' => [
    // Default presets...

    // Custom presets
    'product_card' => [
        'dimensions' => '300x300',
        'format' => 'webp',
        'fit' => 'crop',
        'quality' => 90
    ],
    'banner' => [
        'dimensions' => '1920x400',
        'format' => 'jpg',
        'fit' => 'crop',
        'quality' => 95
    ],
    'mobile_hero' => [
        'dimensions' => '768x400',
        'format' => 'webp',
        'fit' => 'crop',
        'quality' => 85
    ],
],
```

### Using Custom Presets

[](#using-custom-presets)

```
use MacCesar\LaravelGlideEnhanced\Facades\Img;

// Using Img facade
$cardImage = Img::preset('products/image.jpg', 'product_card');
$bannerImage = Img::preset('banners/hero.jpg', 'banner');

// Using HasImages trait
$product = Product::find(1);
$cardImage = $product->getImagePreset('main', 'product_card');
$bannerImage = $product->getImagePreset('main', 'banner');
```

### Preset Best Practices

[](#preset-best-practices)

1. **thumbnail**: Perfect for user avatars, small product images in lists
2. **medium**: Ideal for product cards, blog post featured images
3. **large**: Best for hero images, detailed product views
4. **social**: Optimized for social media sharing (Facebook, Twitter, LinkedIn)

**Performance Tips:**

- Use WebP format for modern browsers (better compression)
- Use JPG for social media sharing (better compatibility)
- Crop fit mode for consistent dimensions, max fit mode to preserve aspect ratio

### Responsive Images with srcset

[](#responsive-images-with-srcset)

The package provides a convenient way to generate srcset attributes for responsive images with different pixel densities:

```
use MacCesar\LaravelGlideEnhanced\Facades\Img;

// Generate srcset for 1x, 2x, and 3x pixel densities
Img::srcset('path/to/image.jpg', ['w' => 300, 'fm' => 'webp']);
// Output: "/glide/storage/path/to/image.jpg?w=300&fm=webp 1x, /glide/storage/path/to/image.jpg?w=600&fm=webp 2x, /glide/storage/path/to/image.jpg?w=900&fm=webp 3x"

// Control the maximum density factor (e.g., up to 2x)
Img::srcset('path/to/image.jpg', ['w' => 300, 'h' => 200, 'fm' => 'webp'], 2);
// Output: "/glide/storage/path/to/image.jpg?w=300&h=200&fm=webp 1x, /glide/storage/path/to/image.jpg?w=600&h=400&fm=webp 2x"
```

Quick Reference
---------------

[](#quick-reference)

### Common Use Cases

[](#common-use-cases)

```
// Blog post featured image
$blog->getImagePreset('featured', 'large');

// User avatar
$user->getImagePreset('avatar', 'thumbnail');

// Product gallery
$product->getImageWebpUrl('gallery_1', ['w' => 600]);

// Social sharing image
$post->getImagePreset('cover', 'social');

// Responsive hero image
Img::srcset('hero/main.jpg', ['w' => 800, 'fm' => 'webp']);
```

### Most Used Glide Parameters

[](#most-used-glide-parameters)

ParameterValuesDescriptionExample`w`integerWidth in pixels`'w' => 400``h`integerHeight in pixels`'h' => 300``fit`crop, max, fill, stretchHow image should fit dimensions`'fit' => 'crop'``fm`webp, jpg, png, gifOutput format`'fm' => 'webp'``q`0-100Quality (lower = smaller file)`'q' => 90``blur`0-100Blur effect`'blur' => 5``bright`-100 to 100Brightness adjustment`'bright' => 10``mark`pathWatermark image path`'mark' => 'logo.png'``markpos`positionWatermark position`'markpos' => 'bottom-right'`### Fit Mode Reference

[](#fit-mode-reference)

- **crop**: Crops image to exact dimensions (may cut off parts)
- **max**: Resizes to fit within dimensions (preserves aspect ratio)
- **fill**: Fills dimensions exactly (may stretch image)
- **stretch**: Stretches to exact dimensions (ignores aspect ratio)

### Applying Watermarks

[](#applying-watermarks)

You can apply watermarks to your images using the following parameters:

```
use MacCesar\LaravelGlideEnhanced\Facades\Img;

// Apply watermark
Img::url('path/to/image.jpg', ['w' => 600, 'mark' => 'watermarks/logo.png', 'markw' => 200, 'markpos' => 'bottom-right', 'markalpha' => 60]);

// Using HasImages trait with watermark
$product->getImageUrl('main', '600', 'jpg', 'watermarks/logo.png', [
    'markw' => 200,
    'markpos' => 'bottom-right',
    'markalpha' => 60
]);
```

> **Important note**: The watermark image must exist at the specified path within `storage/app/public/`. For example, if you use `'mark' => 'watermarks/logo.png'`, the file should be located at `storage/app/public/watermarks/logo.png`.

Usage in Blade Templates
------------------------

[](#usage-in-blade-templates)

### Basic Image Display

[](#basic-image-display)

```
{{-- Product with optimized image --}}
@php
    $product = App\Models\Product::find(1);
@endphp

```

### Responsive Images

[](#responsive-images)

```

```

### Product Gallery

[](#product-gallery)

```

    @foreach(['gallery_1', 'gallery_2', 'gallery_3', 'gallery_4'] as $photo)
        @if($product->{$photo})

        @endif
    @endforeach

```

### Blog Post with Social Meta

[](#blog-post-with-social-meta)

```
@php
    $blog = App\Models\Blog::find(1);
@endphp

        {{ $blog->title }}

        {!! $blog->content !!}

```

### E-commerce Product Card

[](#e-commerce-product-card)

```

        {{ $product->name }}
        {{ $product->description }}

            ${{ $product->price }}

                Add to Cart

```

Cache Cleaning
--------------

[](#cache-cleaning)

To clean the image cache, use the command:

```
php artisan images:clean-cache
```

To clean only images older than a specific number of days:

```
php artisan images:clean-cache --days=7
```

Components Registered
---------------------

[](#components-registered)

This package registers the following components in Laravel:

- **Routes**: A route with the prefix `/glide/` (configurable via the `routes.prefix` config)
- **Services**: A singleton `image-processor` in the container
- **Facade**: `ImageProcessor` for easy access to the service
- **Command**: `images:clean-cache` for cache maintenance

Troubleshooting
---------------

[](#troubleshooting)

### Common Issues

[](#common-issues)

#### Images Not Processing

[](#images-not-processing)

**Problem**: Images return original size instead of processed versions.

**Solutions:**

1. Check that the `images.php` config file is published:

    ```
    php artisan vendor:publish --tag=images-config
    ```
2. Verify the disk configuration in `config/images.php`:

    ```
    'disk' => 'public', // or 'local' depending on your setup
    ```
3. Ensure images exist in the specified storage disk:

    ```
    ls -la storage/app/public/
    ```
4. Clear image cache:

    ```
    php artisan images:clean-cache
    ```

#### Route Not Found Errors

[](#route-not-found-errors)

**Problem**: URLs like `/glide/storage/image.jpg` return 404.

**Solutions:**

1. Check that routes are enabled in config:

    ```
    'routes' => [
        'enabled' => true,
        'prefix' => 'glide',
    ],
    ```
2. Clear route cache:

    ```
    php artisan route:clear
    php artisan config:clear
    ```
3. Verify routes are registered:

    ```
    php artisan route:list | grep glide
    ```

#### WebP Images Not Working

[](#webp-images-not-working)

**Problem**: WebP images not displaying in some browsers.

**Solutions:**

1. Provide fallback using `` element:

    ```

    ```
2. Check server WebP support by testing a direct URL

#### Performance Issues

[](#performance-issues)

**Problem**: Slow image loading or processing.

**Solutions:**

1. Implement image preloading for critical images:

    ```

    ```
2. Use appropriate image formats:

    - WebP for modern browsers (smaller files)
    - JPG for photos with many colors
    - PNG for images with transparency
3. Optimize cache settings in `config/images.php`:

    ```
    'cache' => [
        'lifetime' => 90, // Increase cache lifetime
        'path' => 'cache/glide',
    ],
    ```
4. Use CDN for static assets in production

### FAQ

[](#faq)

**Q: Can I use this with external storage like S3?**A: Currently, the package works only with local storage disks (`local` and `public`). External storage support is planned for future versions.

**Q: How do I create custom presets?**A: Add them to your `config/images.php` file under the `presets` array. See the "Custom Presets" section above.

**Q: Can I change the route prefix?**A: Yes, modify the `routes.prefix` value in your config file. Remember to clear caches after changes.

**Q: How do I disable the package routes?**A: Set `routes.enabled` to `false` in your config file if you want to implement custom routing.

**Q: What's the difference between `getImageUrl()` and `getImageWebpUrl()`?**A: `getImageWebpUrl()` uses the ImageProcessor facade and accepts an array of parameters. `getImageUrl()` gives you full control over individual parameters including dimensions, format, and watermarks.

License
-------

[](#license)

MIT

Credits
-------

[](#credits)

Developed by [César Estrada (macCesar)](https://github.com/macCesar)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance57

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Recently: every ~27 days

Total

12

Last Release

286d ago

Major Versions

v1.0.7 → v2.0.02025-07-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/7af07de0a1d9d37dd72e333231101ad2619d700d2cca94cd54fb444ef3476a03?d=identicon)[macCesar](/maintainers/macCesar)

---

Top Contributors

[![macCesar](https://avatars.githubusercontent.com/u/1383124?v=4)](https://github.com/macCesar "macCesar (18 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/maccesar-laravel-glide-enhanced/health.svg)

```
[![Health](https://phpackages.com/badges/maccesar-laravel-glide-enhanced/health.svg)](https://phpackages.com/packages/maccesar-laravel-glide-enhanced)
```

###  Alternatives

[creativeorange/gravatar

A Laravel Gravatar package for retrieving gravatar image URLs or checking the existance of an image.

5467.5M54](/packages/creativeorange-gravatar)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M102](/packages/intervention-image-laravel)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[ralphjsmit/laravel-glide

Auto-magically generate responsive images from static image files.

4719.6k5](/packages/ralphjsmit-laravel-glide)[spatie/laravel-og-image

Generate OG images for your Laravel app

305.2k](/packages/spatie-laravel-og-image)[nikkanetiya/laravel-color-palette

Laravel Wrapper for `ksubileau/color-thief-php`. Grabs the dominant color or a representative color palette from an image. Uses PHP and GD or Imagick.

3312.6k](/packages/nikkanetiya-laravel-color-palette)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
