PHPackages                             sahm-org/sahm-laravel-image-optimizer - 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. sahm-org/sahm-laravel-image-optimizer

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

sahm-org/sahm-laravel-image-optimizer
=====================================

Professional backend image optimization for Laravel with WebP/AVIF conversion, responsive variants, and Lighthouse optimization. No database required.

1.0.1(4mo ago)012MITPHPPHP ^8.2|^8.3CI failing

Since Jan 12Pushed 4mo agoCompare

[ Source](https://github.com/SAHM-ORG/sahm-laravel-image-optimizer)[ Packagist](https://packagist.org/packages/sahm-org/sahm-laravel-image-optimizer)[ Docs](https://github.com/sahm-org/sahm-laravel-image-optimizer)[ RSS](/packages/sahm-org-sahm-laravel-image-optimizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (2)Used By (0)

SAHM Laravel Image Optimizer
============================

[](#sahm-laravel-image-optimizer)

Professional backend image optimization for Laravel 11 &amp; 12. Convert images to WebP/AVIF, generate responsive variants, optimize for Lighthouse and Core Web Vitals. **No database required.**

[![Latest Version](https://camo.githubusercontent.com/d1f67cb4fbce5621c071fbe46f6026bf8bcd011ce8f90b9e3c74b8e8565a0c88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7361686d2f6c61726176656c2d696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sahm/laravel-image-optimizer)[![Total Downloads](https://camo.githubusercontent.com/98a49fe86891c1a5181be36f26ab8a271be231c91f29804b4ca0cbae907de686/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7361686d2f6c61726176656c2d696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sahm/laravel-image-optimizer)[![License](https://camo.githubusercontent.com/8d30f81b2ff84d9b698ad366ca4c514fadeaf8d541847c92c874c4254dc43481/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7361686d2f6c61726176656c2d696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sahm/laravel-image-optimizer)

---

✨ Features
----------

[](#-features)

- ✅ **No Database Required** - File-based storage with JSON metadata
- ✅ **WebP &amp; AVIF Support** - Modern image formats
- ✅ **Responsive Variants** - Automatic generation of multiple sizes
- ✅ **Lighthouse Optimized** - Pass Core Web Vitals (LCP, FCP)
- ✅ **Native PHP** - Uses Imagick or GD (no external dependencies)
- ✅ **Smart Processing** - Automatic quality detection
- ✅ **Queue Support** - Background processing for large images
- ✅ **Blur Placeholders** - LQIP (Low Quality Image Placeholders)
- ✅ **CDN Ready** - Works with any CDN
- ✅ **Artisan Commands** - Bulk optimization &amp; cleanup
- ✅ **Presets** - Predefined configs (avatar, thumbnail, hero, etc.)
- ✅ **70-80% Size Reduction** - Without visible quality loss

---

📋 Requirements
--------------

[](#-requirements)

- **PHP:** 8.2 or higher
- **Laravel:** 11.x or 12.x
- **Extensions:** Imagick (preferred) or GD

---

🚀 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require sahm-org/sahm-laravel-image-optimizer
```

Publish configuration:

```
php artisan vendor:publish --tag=image-optimizer-config
```

🎯 Quick Start
-------------

[](#-quick-start)

### Basic Usage

[](#basic-usage)

```
use SAHM\ImageOptimizer\Facades\ImageOptimizer;

// Optimize uploaded image
$imageData = ImageOptimizer::optimize($request->file('photo'));

// Get image data
$data = $imageData->toArray();
/*
[
    'hash' => 'a3f7b2c1...',
    'src' => '/storage/images/optimized/.../photo.webp',
    'srcset' => '...photo-320w.webp 320w, ...photo-640w.webp 640w, ...',
    'sizes' => '100vw',
    'width' => 1920,
    'height' => 1080,
    'blur_placeholder' => 'data:image/webp;base64,...',
    'is_lcp' => false,
    'alt' => '',
    'variants' => [...],
]
*/
```

### With Options

[](#with-options)

```
$imageData = ImageOptimizer::optimize($request->file('photo'), [
    'quality' => 85,
    'sizes' => [320, 640, 1024, 1920],
    'is_lcp' => true,
    'alt' => 'Hero image',
]);
```

### Using Presets

[](#using-presets)

```
// Avatar preset
$avatar = ImageOptimizer::optimize($request->file('avatar'), [
    'preset' => 'avatar',
]);

// Hero preset (optimized for LCP)
$hero = ImageOptimizer::optimize($request->file('hero'), [
    'preset' => 'hero',
]);
```

### Retrieve Optimized Image

[](#retrieve-optimized-image)

```
// By hash (store this in your database)
$hash = 'a3f7b2c1...';
$imageData = ImageOptimizer::get($hash);

if ($imageData) {
    echo $imageData->src;
    echo $imageData->srcset;
}
```

🎨 Frontend Integration
----------------------

[](#-frontend-integration)

### Laravel Blade

[](#laravel-blade)

```
@if($imageData)

@endif
```

### Inertia/Vue

[](#inertiavue)

```
// Controller
return Inertia::render('Page', [
    'hero' => ImageOptimizer::optimize($file, ['preset' => 'hero'])->toArray(),
]);
```

```

```

🛠 Artisan Commands
------------------

[](#-artisan-commands)

```
# Check system info
php artisan image-optimizer:info

# Optimize directory
php artisan image-optimizer:optimize storage/app/public/uploads --quality=85

# Cleanup old images
php artisan image-optimizer:cleanup --days=30
```

📊 Performance
-------------

[](#-performance)

### Typical Results:

[](#typical-results)

MetricBeforeAfterDownload table as XLSX fileDownload table as XLSX fileFile Size2.5 MB650 KB (74% reduction)Lighthouse Performance6594LCP4.2s1.8sFCP3.1s1.2s🏢 About SAHM
------------

[](#-about-sahm)

Created and maintained by SAHM.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance78

Regular maintenance activity

Popularity5

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

121d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11aa19ceedec2db7d877c2b99332662395573e8527548f86d5da0bab59fee9c8?d=identicon)[aboalgoud](/maintainers/aboalgoud)

---

Tags

laravelimagegdimagickperformanceoptimizationResponsive ImagesWebpaviflighthousecore-web-vitalslcpsahm

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sahm-org-sahm-laravel-image-optimizer/health.svg)

```
[![Health](https://phpackages.com/badges/sahm-org-sahm-laravel-image-optimizer/health.svg)](https://phpackages.com/packages/sahm-org-sahm-laravel-image-optimizer)
```

###  Alternatives

[intervention/image-laravel

Laravel Integration of Intervention Image

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

Image manipulation library for Laravel 5 based on Imagine and inspired by Croppa for easy url based manipulation

270248.2k5](/packages/folklore-image)[thapp/jitimage

Just in time image manipulation.

997.5k1](/packages/thapp-jitimage)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[danihidayatx/image-optimizer

Optimize your Filament images before they reach your database. Forked from joshembling/image-optimizer for Filament v4 &amp; v5 support.

254.4k](/packages/danihidayatx-image-optimizer)

PHPackages © 2026

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