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

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

baaaaane/image-optimizer
========================

Image optimizer

v1.0.2(6y ago)1892[1 issues](https://github.com/baaane/image-optimizer/issues)MITPHPPHP ^7.2

Since Jun 24Pushed 6y ago1 watchersCompare

[ Source](https://github.com/baaane/image-optimizer)[ Packagist](https://packagist.org/packages/baaaaane/image-optimizer)[ RSS](/packages/baaaaane-image-optimizer/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Image Optimizer
===============

[](#image-optimizer)

This package can generate different size of optimized images (Thumbnail-Mobile-Desktop). Here's how you can use it:

```
use Baaane\ImageOptimizer\Action\ImageOptimizer;

$imageOptimizer = new ImageOptimizer($defaultPath);

$imageOptimizer->upload($_FILES['filename']);
```

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

[](#installation)

You can install the package via github or composer

```
git clone https://github.com/baaane/image-optimizer.git

composer require baaaaane/image-optimizer
```

Tools
-----

[](#tools)

This package is required in this library to optimize the image:

- [image-optimizer](https://github.com/spatie/image-optimizer)

Here's how to install via composer:

```
composer require spatie/image-optimizer
```

Instructions
------------

[](#instructions)

The filenames can be randomized or customized by the user.

#### UploadFile from Laravel's request. (OPTIONAL)

[](#uploadfile-from-laravels-request-optional)

```
$imageOptimizer->uploadRequestFile($request->file('filename'));
```

#### Set File Path - use it before upload() (OPTIONAL)

[](#set-file-path---use-it-before-upload-optional)

```
$imageOptimizer->setPath($optionalPath)->upload();
```

#### Customizable Name (OPTIONAL)

[](#customizable-name-optional)

```
$new_name = [
    'new_name' => 'new_name1'
];
```

#### Customizable Size (FORMAT: WIDTH, HEIGHT) (OPTIONAL)

[](#customizable-size-format-width-height-optional)

```
$size = [
    'size' => $imageOptimizer->setThumbnailSize(width,height)
                            ->setMobileSize(width,height)
                            ->setDesktopSize(width,height)
                            ->get(),
];
```

#### For multiple uploads, use this line of code for re-arrange the array before pass it to imageOptimizer-&gt;upload():

[](#for-multiple-uploads-use-this-line-of-code-for-re-arrange-the-array-before-pass-it-to-imageoptimizer-upload)

```
$data = $imageOptimizer->reArray($data_merge);
```

#### Delete Original File - use it before upload() (OPTIONAL)

[](#delete-original-file---use-it-before-upload-optional)

```
$imageOptimizer->deleteOriginalFile()->upload();
```

#### Parameter for upload should be an array. It should look like this:

[](#parameter-for-upload-should-be-an-array-it-should-look-like-this)

```
[
    'name' => 'uploaded-image.jpg',
    'type' => 'image/jpeg',
    'size' => 542,
    'tmp_name' => __DIR__. '/_files/test.jpg',
    'error' => 0,
    'new_name' => 'new_name1',
    'new_size' => [
        'thumbnail' => [
            'width' => 200,
            'height' => 200
        ]
        'mobile' => [
            'width' => 691,
            'height' => 961
        ]
        'desktop' => [
            'width' => 1920,
            'height' => 1080
        ]
    ]
]
```

### Sample Single Upload

[](#sample-single-upload)

```
// Before merge
$_FILES = [
    'filename' => [
        'name' => 'uploaded-image.jpg',
        'type' => 'image/jpeg',
        'size' => 542,
        'tmp_name' =>	__DIR__. '/_files/test.jpg',
        'error' => 0,
    ]
];

// OPTIONAL PARAMETER: If the input post is string, convert it to array
$new_name = [
	'new_name' => 'new_name1'
];

// OPTIONAL PARAMETER: If the input post is string, convert it to array
$new_size = [
    'new_size' => $imageOptimizer->setThumbnailSize(200,200)
                                ->setMobileSize(691,961)
                                ->setDesktopSize(1920,1080)
                                ->get(),
];

// Then merge
$data = array_merge($_FILES['filename'], $new_name, $new_size);

// OPTIONAL PARAMETER: desired path of uploaded files
$path = __DIR__. '/_files';

$imageOptimizer = new ImageOptimizer($defaultPath);
$imageOptimizer->setPath($optionalPath)->upload($data);
```

### Sample Multiple Upload

[](#sample-multiple-upload)

```
$_FILES = [
    'filename' => [
        'name' => [
            0 => 'uploaded-image.jpg',
            1 => 'uploaded-image1.jpg',
        ],
        'type' => [
            0 => 'image/jpeg',
            1 => 'image/jpeg',
        ],
        'size' => [
            0 => 542,
            1 => 542,
        ],
        'tmp_name' => [
            0 => __DIR__. '/_files/test.jpg',
            1 => __DIR__. '/_files/test1.jpg',
        ],
        'error' => [
            0 => 0,
            1 => 0,
        ]
    ]
];

// OPTIONAL PARAMETER: If the input post is string, convert it to array
$new_name = [
    'new_name' => ['new_name1', 'new_name2']
];

// OPTIONAL PARAMETER: If the input post is string, convert it to array
$size = [
    'new_size' => [
        $imageOptimizer->setThumbnailSize(200,200)
                        ->setMobileSize(691,961)
                        ->setDesktopSize(800,750)
                        ->get(),
        $imageOptimizer->setThumbnailSize()
                        ->setMobileSize(345,789)
                        ->setDesktopSize(0,0)
                        ->get(),
    ]
];

// Then merge
$data_merge = array_merge($_FILES['filename'], $new_name, $new_size);

// Re-arrange the merge data array
$data = $imageOptimizer->reArray($data_merge);

// OPTIONAL PARAMETER: desired path of uploaded files
$path = __DIR__. '/_files';

$imageOptimizer = new ImageOptimizer(defaultPath);
$imageOptimizer->setPath($optionalPath)->upload($data);
```

#### Sample retrieve files after uploading. Return an array upon success.

[](#sample-retrieve-files-after-uploading-return-an-array-upon-success)

```
// single upload file
Array
(
  0 => Array (
    "thumbnail" => "/_files/thumbnail_new_name1.jpg"
    "mobile" => "/_files/mobile_new_name1.jpg"
    "desktop" => "/_files/desktop_new_name1.jpg"
  )
)

// multiple upload file
Array
(
  0 => Array (
    "thumbnail" => "/_files/thumbnail_new_name1.jpg"
    "mobile" => "/_files/mobile_new_name1.jpg"
    "desktop" => "/_files/desktop_new_name1.jpg"
  )
  1 => Array (
    "thumbnail" => "/_files/thumbnail_new_name2.jpg"
    "mobile" => "/_files/mobile_new_name2.jpg"
    "desktop" => "/_files/desktop_new_name2.jpg"
  )
)
```

Example conversions
-------------------

[](#example-conversions)

Here are the example conversions done by this package.

### Original:

[](#original)

##### 1920 x 1080 | JPEG | 272KB

[](#1920-x-1080--jpeg--272kb)

[![Original](https://github.com/baaane/image-uploader/raw/master/storage/app/public/test.jpg?raw=true)](https://github.com/baaane/image-uploader/blob/master/storage/app/public/test.jpg?raw=true)

### Optimized and Converted to Desktop | Mobile | Thumbnail:

[](#optimized-and-converted-to-desktop--mobile--thumbnail)

##### Desktop 1920 x 1080 | JPEG | 218KB

[](#desktop-1920-x-1080--jpeg--218kb)

[![Optimized](https://github.com/baaane/image-uploader/raw/master/storage/app/public/desktop_new_name1.jpg?raw=true)](https://github.com/baaane/image-uploader/blob/master/storage/app/public/desktop_new_name1.jpg?raw=true)

##### Mobile 690 x 960 | JPEG | 50KB

[](#mobile-690-x-960--jpeg--50kb)

[![Optimized](https://github.com/baaane/image-uploader/raw/master/storage/app/public/mobile_new_name1.jpg?raw=true)](https://github.com/baaane/image-uploader/blob/master/storage/app/public/mobile_new_name1.jpg?raw=true)

##### Thumbnail 300x300 | JPEG | 14KB

[](#thumbnail-300x300--jpeg--14kb)

[![Optimized](https://github.com/baaane/image-uploader/raw/master/storage/app/public/thumbnail_new_name1.jpg?raw=true)](https://github.com/baaane/image-uploader/blob/master/storage/app/public/thumbnail_new_name1.jpg?raw=true)

Credits
-------

[](#credits)

- [Spatie](https://github.com/spatie)This package has been inspired by [spatie/image-optimizer](https://github.com/spatie/image-optimizer)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/baaane/image-uploader/blob/master/LICENSE) for more information.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

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

Every ~36 days

Total

3

Last Release

2485d ago

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

v1.0.1PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/68476c6c9670169e067caa0fe09eeec6041062a5fffdb583cebf01e3140132f5?d=identicon)[baaane](/maintainers/baaane)

---

Top Contributors

[![baaane](https://avatars.githubusercontent.com/u/7714520?v=4)](https://github.com/baaane "baaane (27 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M462](/packages/pimcore-pimcore)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.5k](/packages/larastan-larastan)[spatie/image

Manipulate images with an expressive API

1.4k58.5M175](/packages/spatie-image)[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.3k449.3k30](/packages/tightenco-jigsaw)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9742.3M121](/packages/roots-acorn)

PHPackages © 2026

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