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

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

avnsh1111/laravel-image-optimizer
=================================

A Laravel package that automatically optimizes images uploaded through the application.

v1(3y ago)57MITPHPPHP ^7.2|^8.2

Since Apr 24Pushed 3y ago1 watchersCompare

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

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

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

[](#laravel-image-optimizer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1cce6590e902c28c44c95a173e8e17a3c27c510f57ad76f209e1e468973f7491/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61766e7368313131312f6c61726176656c2d696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/avnsh1111/laravel-image-optimizer)[![Total Downloads](https://camo.githubusercontent.com/57f8195351293a8d7abb90f486e70fe6675ef59ab9cde022aafb904f75f66367/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61766e7368313131312f6c61726176656c2d696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/avnsh1111/laravel-image-optimizer)

Laravel Image Optimizer is a package that provides an easy way to optimize and resize images in your Laravel applications.

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

[](#installation)

You can install the package via composer:

```
composer require avnsh1111/laravel-image-optimizer
```

Usage
-----

[](#usage)

To use the package, you need to create a model that uses the `OptimizeImage` trait. The trait provides a set of options for optimizing and resizing your images.

Here's an example of a model using the `OptimizeImage` trait:

```
use LaravelImageOptimizer\Traits\OptimizeImage;
use Illuminate\Database\Eloquent\Model;

class TestImage extends Model
{
    use OptimizeImage;

    protected $fillable = ['name'];

    protected static $optimizeImages = [
        'name' => [
            'name_only' => true,
            'base_path' => 'public/uploads/images/',
            'quality' => 85,
            'width' => 800,
            'height' => 800,
            'keep_files' => false // This value will be overridden by the $keep_files property
        ],
    ];
}
```

### Options

[](#options)

- `name_only`: Set to `true` if you want to store just the file name in the database. Set to `false` if you want to store the full path.
- `base_path`: The base path where your images will be stored.
- `quality`: The quality of the optimized image (from 0 to 100).
- `width`: The maximum width of the optimized image.
- `height`: The maximum height of the optimized image.
- `keep_files`: Set to `true` if you want to keep the original image file when updating or deleting a record. Set to `false` if you want to remove the image file when updating or deleting a record.

### Example

[](#example)

Here's an example of how to use the package to optimize and resize an image:

```
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;

// Fake storage for testing
Storage::fake('public');

// Create a test image
$image = Image::make(UploadedFile::fake()->image('test-image.jpg', 2000, 2000));
$imagePath = 'public/uploads/images/test-image.jpg';
Storage::put($imagePath, (string)$image->encode());

// Check if the image exists in storage
$this->assertTrue(Storage::exists($imagePath));

// Create a TestImage model
$testImage = TestImage::create(['name' => 'test-image.jpg']);

// Load the optimized image
$optimizedImage = Image::make(Storage::get($imagePath));

// Check if the optimized image dimensions are correct
$this->assertLessThanOrEqual(800, $optimizedImage->width());
$this->assertLessThanOrEqual(800, $optimizedImage->height());
```

Testing
-------

[](#testing)

To run the tests, execute the following command:

```
composer test
```

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

[](#contributing)

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

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Avinash Rathod](https://github.com/avnsh1111)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Unknown

Total

1

Last Release

1115d ago

### Community

Maintainers

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

---

Top Contributors

[![Avnsh1111](https://avatars.githubusercontent.com/u/28943172?v=4)](https://github.com/Avnsh1111 "Avnsh1111 (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/image

Manipulate images with an expressive API

1.4k54.4M138](/packages/spatie-image)[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)

PHPackages © 2026

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