PHPackages                             guizoxxv/laravel-multi-size-image - 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. guizoxxv/laravel-multi-size-image

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

guizoxxv/laravel-multi-size-image
=================================

Laravel package to optimize and store images in different sizes in order to load the appropriate one according to the screen size.

v0.2.0(4y ago)389.0k↓100%4MITPHP

Since Aug 30Pushed 6mo ago4 watchersCompare

[ Source](https://github.com/guizoxxv/laravel-multi-size-image)[ Packagist](https://packagist.org/packages/guizoxxv/laravel-multi-size-image)[ RSS](/packages/guizoxxv-laravel-multi-size-image/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (7)Used By (0)

Laravel Multi Size Image
========================

[](#laravel-multi-size-image)

Laravel package to optimize and store images in different sizes in order to load the appropriate one according to the screen size.

[![schema](schema.png)](schema.png)

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

[](#requirements)

- To resize the images this package uses the [Intervention library](http://image.intervention.io/) which requires a image library like [GD](https://www.php.net/manual/en/book.image.php) or [ImageMagick](https://www.php.net/manual/en/book.imagick.php).
- To optimize the images this package uses [image-optimizer](https://github.com/spatie/image-optimizer) package which requires [optimizers](https://github.com/spatie/image-optimizer#optimization-tools) to be present in your system.

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

[](#installation)

Require the package via Composer:

```
$ composer require guizoxxv/laravel-multi-size-image

```

Configuration
-------------

[](#configuration)

Publish the package configuration file to your Laravel project to change the default behavior.

```
$ php artisan vendor:publish --provider="Guizoxxv\LaravelMultiSizeImage\MultiSizeImageServiceProvider"

```

A `config/multiSizeImage.php` file will be added in your project.

Usage
-----

[](#usage)

### 1. Instantiate

[](#1-instantiate)

To apply Multi Size Image first you must create an instance of it.

```
use Guizoxxv\LaravelMultiSizeImage\MultiSizeImage;

...

$multiSizeImage = new MultiSizeImage();
```

### 2. Process image

[](#2-process-image)

Call the `processImage` method passing the file path as the first argument.

```
$filePath = Storage::path('folder/file.png');

$multiSizeImage->processImage($filePath);
```

> The file path must be absolute.

The method returns an array of strings with the full path of the generated files.

#### 2.1. Mime types

[](#21-mime-types)

Only mime types defined in the `mime_types` array in the `config/multiSizeImage.php` file are considered. If a file with mime type not present is used, it is ignored and the method returns `null`.

> This package is configured to optimize `jpeg` and `png` images. Check the [Optimizing](#optimizing) section to learn how to optimize images with other mime types.

#### 2.2. Output path

[](#22-output-path)

The default behavior is to create the resized image versions in the same path as the original's. To send the images to a different location you can provide the output path as a second optional parameter.

```
$multiSizeImage->processImage($filePath, $outputPath, $basePath);
```

The `basePath` optional parameter can be used to keep the original file path as of this path.

#### 2.3. Resizing

[](#23-resizing)

The resizable values are defined by the `sizes` array in the `config/multiSizeImage.php` file. This array has the keys as the size identification and the value as the size for the image to be resized to.

```
'sizes' => [
    'tb' => 150,
    'sm' => 300,
    'lg' => 1024,
]
```

Above are the default values. The biggest dimension is considered when resizing and the aspect ratio is kept. An auto-generated name will be used as the new file name. The size identification is used as a suffix in the file name to distinguish which will be loaded.

> **Example:**
>
> If a 2000x1000px (width x height) image is used, the following files will be generated:
>
> -  (1024x512px)
> -  (300x150px)
> -  (150x75px)

If the image width and height are lower than the specified resize value, the image is not resized and the new file is generated without a suffix.

> **Example:**
>
> If a 100x200px (width x height) image is used, the following files will be generated:
>
> - 5f4bd0444e9dd.png (100x200px)
> -  (75x150px)

#### 2.4. File name

[](#24-file-name)

If you want to keep the original's file name instead of using an auto-generated one, set `keep_original_name` to `true` in the `config/multiSizeImage.php` file.

You can also provide an optional custom name as a forth parameter to the `processImage` method.

```
$multiSizeImage->processImage($filePath, $outputPath, $basePath, $fileName);
```

#### 2.5. Optimizing

[](#25-optimizing)

By default the newly generate image is also optimized using [image-optimizer](https://github.com/spatie/image-optimizer) package with [JpegOptim](http://freshmeat.sourceforge.net/projects/jpegoptim), [Optipng](http://optipng.sourceforge.net/) and [Pngquant 2](https://pngquant.org/) optimizers with the following `OptimizerChain`.

```
$optimizerChain = (new OptimizerChain)
    ->addOptimizer(new Jpegoptim([
        '-m85',
        '--strip-all',
        '--all-progressive',
    ]))
    ->addOptimizer(new Pngquant([
        '--force',
    ]))
    ->addOptimizer(new Optipng([
        '-i0',
        '-o2',
        '-quiet',
    ]));
```

To override the default optimization behavior you can provide a custom `OptimizerChain` as an argument when instantiating `MultiSizeImage`.

```
use Guizoxxv\LaravelMultiSizeImage\MultiSizeImage;
use Spatie\ImageOptimizer\Optimizers\Svgo;
use Spatie\ImageOptimizer\Optimizers\Optipng;
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
use Spatie\ImageOptimizer\Optimizers\Pngquant;
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
use Spatie\ImageOptimizer\Optimizers\Cwebp;

...

$optimizerChain = (new OptimizerChain)
    ->addOptimizer(new Jpegoptim([
        '-m85',
        '--strip-all',
        '--all-progressive',
    ]))
    ->addOptimizer(new Pngquant([
        '--force',
    ]))
    ->addOptimizer(new Optipng([
        '-i0',
        '-o2',
        '-quiet',
    ]))
    ->addOptimizer(new Svgo([
        '--disable=cleanupIDs',
    ]))
    ->addOptimizer(new Gifsicle([
        '-b',
        '-O3'
    ]))
    ->addOptimizer(new Cwebp([
        '-m 6',
        '-pass 10',
        '-mt',
        '-q 90',
    ]));

$multiSizeImage = new MultiSizeImage($optimizerChain);
```

You can also disable optimization by setting `optimize` to `false` in the `config/multiSizeImage.php` file.

#### 2.6. Delete original

[](#26-delete-original)

The default behavior is to delete the original image after processing if the resized files names don't match the original's (changed name or path). If you choose to keep it, set `keep_original_file` to `true` in the `config/multiSizeImage.php` file.

### 3. Render

[](#3-render)

Render the image file according to the screen size.

> Remember to provide a fallback in case the image name does not have a suffix.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance47

Moderate activity, may be stable

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

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 ~64 days

Total

5

Last Release

1822d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/67ccf02679b542b46bd234e02bd7159bcf262a0faa9697ab3305d1269e951b80?d=identicon)[Guizo](/maintainers/Guizo)

---

Top Contributors

[![guizoxxv](https://avatars.githubusercontent.com/u/20052395?v=4)](https://github.com/guizoxxv "guizoxxv (9 commits)")

---

Tags

image-optimizerlaravelphp

### Embed Badge

![Health badge](/badges/guizoxxv-laravel-multi-size-image/health.svg)

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

###  Alternatives

[spatie/image

Manipulate images with an expressive API

1.4k54.4M138](/packages/spatie-image)[league/glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.

2.6k51.2M116](/packages/league-glide)[spatie/laravel-image-optimizer

Optimize images in your Laravel app

1.3k6.5M43](/packages/spatie-laravel-image-optimizer)[jenssegers/imagehash

Perceptual image hashing for PHP

2.1k2.2M5](/packages/jenssegers-imagehash)[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)

PHPackages © 2026

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