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

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

christyoga123/image-optimizer
=============================

A fluent Laravel package for optimizing images - resize, convert formats (WebP, JPG, PNG, AVIF), and reduce file size while maintaining quality

v1.0.0(5mo ago)1970MITPHPPHP ^8.1

Since Jan 20Pushed 5mo agoCompare

[ Source](https://github.com/ChristYoga123/image-optimizer)[ Packagist](https://packagist.org/packages/christyoga123/image-optimizer)[ Docs](https://github.com/christyoga123/laravel-image-optimizer)[ RSS](/packages/christyoga123-image-optimizer/feed)WikiDiscussions main Synced yesterday

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

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

[](#laravel-image-optimizer)

A fluent Laravel package for optimizing images - resize, convert formats (WebP, JPG, PNG, AVIF), and reduce file size while maintaining quality.

[![Latest Version on Packagist](https://camo.githubusercontent.com/6d602158b2d75a9c34c46d22441de67a65ccf6a9f9942ba9da607bef7ecc7d87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636872697374796f67613132332f696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/christyoga123/image-optimizer)[![License](https://camo.githubusercontent.com/4fbe2f5d6ee35373cf32ae982407b34732e969c2dfeefbf7548b025f401cefbc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636872697374796f67613132332f696d6167652d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/christyoga123/image-optimizer)

Features
--------

[](#features)

- 🖼️ **Format Conversion** - Convert images to WebP, JPG, PNG, GIF, AVIF
- 📐 **Smart Resize** - Resize with max width/height while maintaining aspect ratio
- 🎚️ **Quality Control** - Adjustable quality settings for optimal file size
- 🔧 **Fluent API** - Chain methods for clean, readable code
- ⚙️ **Configurable** - Publish and customize default settings
- 🧹 **Auto Cleanup** - Automatic temporary file cleanup

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.x, 11.x, or 12.x
- GD Library or Imagick extension

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

[](#installation)

Install the package via Composer:

```
composer require christyoga123/image-optimizer
```

The package will automatically register its service provider.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

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

This will create a `config/image-optimizer.php` file with all available options.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Christyoga123\ImageOptimizer\ImageOptimizer;

// Process uploaded file and get optimized temp path
$tempPath = ImageOptimizer::make()
    ->toWebp()
    ->maxDimensions(1200, 1200)
    ->quality(85)
    ->process($uploadedFile);

// Do something with the optimized file
Storage::disk('public')->put('images/photo.webp', file_get_contents($tempPath));
```

### Using Facade

[](#using-facade)

```
use Christyoga123\ImageOptimizer\Facades\ImageOptimizer;

$tempPath = ImageOptimizer::make()
    ->toWebp()
    ->maxWidth(800)
    ->process($request->file('image'));
```

### From Request Input

[](#from-request-input)

```
$tempPath = ImageOptimizer::make()
    ->toJpg()
    ->quality(90)
    ->processFromRequest('photo');

if ($tempPath) {
    // File was uploaded and processed
    $user->update(['avatar' => Storage::putFile('avatars', $tempPath)]);
}
```

### From File Path

[](#from-file-path)

```
$tempPath = ImageOptimizer::make()
    ->toPng()
    ->maxDimensions(600, 600)
    ->processFromPath('/path/to/original/image.jpg');
```

### With Default Settings

[](#with-default-settings)

Apply all defaults from config at once:

```
$tempPath = ImageOptimizer::make()
    ->withDefaults()
    ->process($uploadedFile);
```

### Get Size Comparison

[](#get-size-comparison)

```
$optimizer = ImageOptimizer::make()
    ->toWebp()
    ->quality(80)
    ->maxDimensions(1200, 1200);

$tempPath = $optimizer->process($uploadedFile);

$comparison = $optimizer->getSizeComparison($uploadedFile->getRealPath());

// Result:
// [
//     'original_size' => 2500000,
//     'optimized_size' => 450000,
//     'saved_bytes' => 2050000,
//     'saved_percentage' => 82.0
// ]

echo "Saved: " . $optimizer->formatFileSize($comparison['saved_bytes']);
// Output: "Saved: 2.00 MB"
```

### Helper Methods

[](#helper-methods)

```
$optimizer = ImageOptimizer::make();

// Get sanitized filename for storage
$filename = $optimizer->getOptimizedFilename($uploadedFile);
// "my_photo.webp"

// Get current format
$format = $optimizer->getFormat();
// "webp"

// Get temp file path
$path = $optimizer->getTempPath();

// Manual cleanup (usually not needed - destructor handles this)
$optimizer->cleanup();
```

Available Methods
-----------------

[](#available-methods)

### Format Methods

[](#format-methods)

MethodDescription`format(string $format)`Set output format (webp, jpg, png, gif, avif)`toWebp()`Convert to WebP format`toJpg()`Convert to JPEG format`toPng()`Convert to PNG format`toGif()`Convert to GIF format`toAvif()`Convert to AVIF format### Resize Methods

[](#resize-methods)

MethodDescription`maxWidth(int $width)`Set maximum width (maintains aspect ratio)`maxHeight(int $height)`Set maximum height (maintains aspect ratio)`maxDimensions(int $width, int $height)`Set both max width and height### Quality &amp; Settings

[](#quality--settings)

MethodDescription`quality(int $quality)`Set quality 1-100 (affects jpg, webp, avif)`tempDir(string $path)`Set custom temporary directory`withDefaults()`Apply all defaults from config### Process Methods

[](#process-methods)

MethodDescription`process(UploadedFile $file)`Process uploaded file`processUploadedFile(UploadedFile $file)`Alias for process()`processFromPath(string $path)`Process from file path`processFromRequest(string $inputName)`Process from request input nameConfiguration
-------------

[](#configuration)

After publishing, you can customize these options in `config/image-optimizer.php`:

```
return [
    // Image driver: 'gd' or 'imagick'
    'driver' => env('IMAGE_OPTIMIZER_DRIVER', 'gd'),

    // Default output format
    'format' => env('IMAGE_OPTIMIZER_FORMAT', 'webp'),

    // Default quality (1-100)
    'quality' => env('IMAGE_OPTIMIZER_QUALITY', 85),

    // Default max dimensions (used with withDefaults())
    'max_width' => env('IMAGE_OPTIMIZER_MAX_WIDTH', 1200),
    'max_height' => env('IMAGE_OPTIMIZER_MAX_HEIGHT', 1200),

    // Temporary directory for processed files
    'temp_dir' => env('IMAGE_OPTIMIZER_TEMP_DIR', storage_path('app/temp')),
];
```

Integration Examples
--------------------

[](#integration-examples)

### With Spatie Media Library

[](#with-spatie-media-library)

```
use Christyoga123\ImageOptimizer\ImageOptimizer;

// Optimize before adding to media collection
$tempPath = ImageOptimizer::make()
    ->toWebp()
    ->maxDimensions(1200, 1200)
    ->quality(85)
    ->process($request->file('photo'));

$model->addMedia($tempPath)
    ->usingFileName('optimized-photo.webp')
    ->toMediaCollection('photos');
```

### With Laravel Storage

[](#with-laravel-storage)

```
$optimizer = ImageOptimizer::make()
    ->toWebp()
    ->maxWidth(800);

$tempPath = $optimizer->process($request->file('image'));
$filename = $optimizer->getOptimizedFilename($request->file('image'));

// Store to disk
$path = Storage::disk('public')->putFileAs('uploads', $tempPath, $filename);

return response()->json(['path' => $path]);
```

### In Form Request

[](#in-form-request)

```
// app/Http/Requests/StorePhotoRequest.php
public function passedValidation()
{
    if ($this->hasFile('photo')) {
        $tempPath = ImageOptimizer::make()
            ->withDefaults()
            ->process($this->file('photo'));

        $this->merge([
            'optimized_photo_path' => $tempPath
        ]);
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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)

- [ChristYoga123](https://github.com/christyoga123)
- [Intervention Image](https://image.intervention.io/)

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance71

Regular maintenance activity

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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

165d ago

### Community

Maintainers

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

---

Top Contributors

[![ChristYoga123](https://avatars.githubusercontent.com/u/93587043?v=4)](https://github.com/ChristYoga123 "ChristYoga123 (1 commits)")

---

Tags

laravelimageresizecompressoptimizerinterventionWebp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[intervention/image-laravel

Laravel Integration of Intervention Image

1588.9M182](/packages/intervention-image-laravel)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.5M85](/packages/unisharp-laravel-filemanager)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

506516.3k29](/packages/bkwld-croppa)[hasinhayder/tyro-dashboard

Tyro Dashboard - Beautiful admin dashboard for managing Tyro roles, privileges, users, and settings

5443.8k](/packages/hasinhayder-tyro-dashboard)[reliqarts/laravel-guided-image

Simplified and ready image manipulation for Laravel via intervention image.

351.7k](/packages/reliqarts-laravel-guided-image)[danihidayatx/image-optimizer

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

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

PHPackages © 2026

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