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

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

joshembling/image-optimizer
===========================

Optimize your Filament images before they reach your database.

v1.6.4(7mo ago)111145.4k—5.4%37[3 PRs](https://github.com/joshembling/image-optimizer/pulls)12MITPHPPHP ^8.2CI passing

Since Sep 19Pushed 4mo ago4 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (25)Used By (12)

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 using or upgrading to Filament v4.

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()
    ->maxImageWidth(1024)
    ->maxImageHeight(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')
	->maxImageWidth(1024)
	->maxImageHeight(768)
	->resize(50),
```

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

SpatieMediaLibraryFileUpload::make('attachment')
    ->image()
	->optimize('webp')
	->maxImageWidth(1024)
	->maxImageHeight(768)
    ->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

57

—

FairBetter than 98% of packages

Maintenance71

Regular maintenance activity

Popularity50

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 82.7% 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 ~38 days

Recently: every ~56 days

Total

21

Last Release

211d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.4.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1ec886bd6b22625b8df2b17811443f37daa76ee44c6e053dbb9dc71f0bc6a3a?d=identicon)[joshembling](/maintainers/joshembling)

---

Top Contributors

[![joshembling](https://avatars.githubusercontent.com/u/65712975?v=4)](https://github.com/joshembling "joshembling (81 commits)")[![Autive](https://avatars.githubusercontent.com/u/6318898?v=4)](https://github.com/Autive "Autive (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![FinnPaes](https://avatars.githubusercontent.com/u/71390226?v=4)](https://github.com/FinnPaes "FinnPaes (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 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)")[![lucasvieira2902](https://avatars.githubusercontent.com/u/66380573?v=4)](https://github.com/lucasvieira2902 "lucasvieira2902 (1 commits)")[![maytham553-elite](https://avatars.githubusercontent.com/u/171784268?v=4)](https://github.com/maytham553-elite "maytham553-elite (1 commits)")[![SupianIDz](https://avatars.githubusercontent.com/u/37969970?v=4)](https://github.com/SupianIDz "SupianIDz (1 commits)")

---

Tags

filamentfilament-pluginfilamentphpimagelaraveloptimizationlaravelimageimage-optimizeroptimizationfilamentfilamentphpjoshembling

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[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)[webplusm/gallery-json-media

a filament media storing in a Json field

196.0k](/packages/webplusm-gallery-json-media)

PHPackages © 2026

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