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

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

adman9000/image-optimizer
=========================

Optimize your Filament images before they reach your database.

05PHP

Since Oct 27Pushed 4mo agoCompare

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

READMEChangelogDependenciesVersions (1)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 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

20

—

LowBetter than 14% of packages

Maintenance52

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

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)")

### Embed Badge

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

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

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)[humanmade/tachyon-plugin

Rewrites WordPress image URLs to use Tachyon

87338.5k2](/packages/humanmade-tachyon-plugin)

PHPackages © 2026

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