PHPackages                             henset11/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. henset11/image-optimizer

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

henset11/image-optimizer
========================

Optimize your Filament images before they reach your database.

v4.0.0(9mo ago)02MITPHPPHP ^8.2

Since Aug 14Pushed 8mo agoCompare

[ Source](https://github.com/henset11/image-optimizer)[ Packagist](https://packagist.org/packages/henset11/image-optimizer)[ Docs](https://github.com/joshembling/image-optimizer)[ GitHub Sponsors](https://github.com/joshembling)[ RSS](/packages/henset11-image-optimizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Caution

There are no plans to extend this plugin's lifetime beyond Filament v3. Please do not plan to use this in production if you are thinking of upgrading to Filament v4 when it is released in the summer of 2025.

Optimize your Filament images before they reach your database.
==============================================================

[](#optimize-your-filament-images-before-they-reach-your-database)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e754a7298c073df6d20d2c72a2c7aae0dad7c6085c59f95cc4cb045ff03bbbf9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f7368656d626c696e672f696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/joshembling/image-optimizer)[![Total Downloads](https://camo.githubusercontent.com/74578624c1d7b190601396e8b256aa8ce1d759c48d0114aa18489db0e9708eb5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f7368656d626c696e672f696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/joshembling/image-optimizer)

When you currently upload an image using the native Filament component `FileUpload`, the original file is saved without any compression or conversion.

Additionally, if you upload an image and use conversions with `SpatieMediaLibraryFileUpload`, the original file is saved with its corresponding versions provided on your model.

What if you'd rather convert and reduce the image(s) before reaching your database/S3 bucket? Especially in the case where you know you'll never need to save the original image sizes the user has uploaded.

🤳 **This is where Filament Image Optimizer comes in**.

You use the same components as you have been doing and have access to two additional methods for maximum optimization, saving you a lot of disk space in the process. 🎉

Contents
--------

[](#contents)

- [Contents](#contents)
- [Installation](#installation)
- [Usage](#usage)
    - [Optimizing Images](#optimizing-images)
    - [Resizing Images](#resizing-images)
    - [Combining Methods](#combining-methods)
    - [Multiple Images](#multiple-images)
    - [Examples](#examples)
    - [Debugging](#debugging)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [Licence](#license)

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

[](#installation)

You can install the package via composer, which currently works with the latest Filament version (^3.2) and Laravel 10, 11 &amp; 12:

```
composer require joshembling/image-optimizer
```

If you are using Filament 3.0 or 3.1 install with:

```
composer require joshembling/image-optimizer:v1.2
```

Usage
-----

[](#usage)

### Filament version

[](#filament-version)

You must be using [Filament v3.x](https://filamentphp.com/docs/3.x/panels/installation) to have access to this plugin.

For specific versions that match your PHP, Laravel, Filament and Image Optimizer installations please see the table below:

PHPLaravel versionFilament versionImage Optimizer version^8.1^10.0^3.01.2^8.1^10.0^3.11.2^8.1^10.0^3.2~1.3^8.2^10.0, ^11.0^3.2^1.4^8.2^10.0, ^11.0, ^12.0^3.2^1.6### Server

[](#server)

[GD Library](https://www.php.net/manual/en/image.installation.php) must be installed on your server to compress images.

### Optimizing images

[](#optimizing-images)

Before uploading your image, you may choose to optimize it by converting to your chosen format. The file saved to your disk will be the converted version only.

E.g. I want to convert my image to 'webp':

```
use Filament\Forms\Components\FileUpload;

FileUpload::make('attachment')
    ->image()
    ->optimize('webp'),
```

You can do exactly the same using `SpatieMediaLibraryFileUpload`:

```
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;

SpatieMediaLibraryFileUpload::make('attachment')
    ->image()
    ->optimize('webp'),
```

### Resizing images

[](#resizing-images)

You may also want to resize an image by passing in a percentage you would like to reduce the image by. This will also maintain aspect ratio.

E.g. I'd like to reduce my image (1280px x 720px) by 50%:

```
use Filament\Forms\Components\FileUpload;

FileUpload::make('attachment')
    ->image()
    ->resize(50),
```

Uploaded image size is 640px x 360px.

You can do the same using `SpatieMediaLibraryFileUpload`:

```
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;

SpatieMediaLibraryFileUpload::make('attachment')
    ->image()
    ->resize(50),
```

### Add maximum width and/or height

[](#add-maximum-width-andor-height)

You can also add a maximum width and/or height to the image. This will resize the image to the maximum width and/or height, maintaining the aspect ratio.

```
use Filament\Forms\Components\FileUpload;

FileUpload::make('attachment')
    ->image()
    ->maxWidth(1024)
    ->maxHeight(768),
```

### Combining methods

[](#combining-methods)

You can combine these two methods for maximum optimization.

```
use Filament\Forms\Components\FileUpload;

FileUpload::make('attachment')
	->image()
	->optimize('webp')
	->resize(50),
```

```
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;

SpatieMediaLibraryFileUpload::make('attachment')
    ->image()
	->optimize('webp')
    ->resize(50),
```

### Multiple images

[](#multiple-images)

You can also do this with multiple images - all images will be converted to the same format and reduced with the same percentage passed in. Just chain on `multiple()` to your upload:

```
use Filament\Forms\Components\FileUpload;

FileUpload::make('attachment')
    ->image()
	->multiple()
	->optimize('jpg')
    ->resize(50),
```

```
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;

SpatieMediaLibraryFileUpload::make('attachment')
    ->image()
	->multiple()
	->optimize('jpg')
    ->resize(50),
```

### Examples

[](#examples)

[![Before](images/before.jpg)](images/before.jpg)

[![After](images/after.jpg)](images/after.jpg)

### Debugging

[](#debugging)

- If you see a 'not found' exception, including "Method `optimize`" or "Method `resize`", ensure you run `composer update` so that your lock file is in sync with your `composer.json`.
- You might see a 'Waiting for size' message and an infinite loading state on the component and the likely cause of this is a CORS issue. This can be quickly be resolved by ensuring you are serving and upload images from the same domain. Check your Javascript console for more information.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Josh Embling](https://github.com/joshembling)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance59

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.6% 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

Unknown

Total

1

Last Release

277d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0eb63c0bc07f5aa98d04f08829bb4c9bc9467c9a34c53143fdddefdd4c8d0506?d=identicon)[henset11](/maintainers/henset11)

---

Top Contributors

[![joshembling](https://avatars.githubusercontent.com/u/65712975?v=4)](https://github.com/joshembling "joshembling (77 commits)")[![Autive](https://avatars.githubusercontent.com/u/6318898?v=4)](https://github.com/Autive "Autive (4 commits)")[![FinnPaes](https://avatars.githubusercontent.com/u/71390226?v=4)](https://github.com/FinnPaes "FinnPaes (2 commits)")[![henset11](https://avatars.githubusercontent.com/u/106941449?v=4)](https://github.com/henset11 "henset11 (1 commits)")[![lucasvieira2902](https://avatars.githubusercontent.com/u/66380573?v=4)](https://github.com/lucasvieira2902 "lucasvieira2902 (1 commits)")[![pavlovpa4o](https://avatars.githubusercontent.com/u/7713916?v=4)](https://github.com/pavlovpa4o "pavlovpa4o (1 commits)")[![SupianIDz](https://avatars.githubusercontent.com/u/37969970?v=4)](https://github.com/SupianIDz "SupianIDz (1 commits)")[![ahmadrio](https://avatars.githubusercontent.com/u/41967704?v=4)](https://github.com/ahmadrio "ahmadrio (1 commits)")[![WillieOng-HK](https://avatars.githubusercontent.com/u/5966527?v=4)](https://github.com/WillieOng-HK "WillieOng-HK (1 commits)")[![cleeimpro](https://avatars.githubusercontent.com/u/46934974?v=4)](https://github.com/cleeimpro "cleeimpro (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laravelimageimage-optimizeroptimizationfilamentfilamentphpjoshembling

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/henset11-image-optimizer/health.svg)

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

###  Alternatives

[joshembling/image-optimizer

Optimize your Filament images before they reach your database.

111145.4k12](/packages/joshembling-image-optimizer)[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)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

320392.1k17](/packages/codewithdennis-filament-select-tree)[dotswan/filament-map-picker

Easily pick and retrieve geo-coordinates using a map-based interface in your Filament applications.

124139.3k2](/packages/dotswan-filament-map-picker)[rawilk/filament-password-input

Enhanced password input component for filament.

52232.4k3](/packages/rawilk-filament-password-input)[guava/filament-modal-relation-managers

Allows you to embed relation managers inside filament modals.

7565.0k4](/packages/guava-filament-modal-relation-managers)

PHPackages © 2026

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