PHPackages                             amir-hossein5/laravel-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. amir-hossein5/laravel-image

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

amir-hossein5/laravel-image
===========================

v2.2.0(4y ago)0211MITPHPPHP ^7.4|^8.0

Since Dec 11Pushed 3y ago1 watchersCompare

[ Source](https://github.com/amirHossein5/laravel-image)[ Packagist](https://packagist.org/packages/amir-hossein5/laravel-image)[ RSS](/packages/amir-hossein5-laravel-image/feed)WikiDiscussions 2.x Synced 3d ago

READMEChangelog (9)Dependencies (3)Versions (12)Used By (0)

Create image with multiple sizes based on [intervention](http://image.intervention.io/) easily.

*for Example:*

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::make($request->image)
  ->setExclusiveDirectory('post')
  ->save();
```

It will save your image in three sizes, which were defined in config file, in path:

- `public/`
    - `images/post/2021/12/2/1638611107/`
        - `1638611107_960_large.png`
        - `1638611107_960_medium.png`
        - `1638611107_960_small.png`

Prerequisites
-------------

[](#prerequisites)

- Laravel `^8.0|^9.0`
- PHP `^7.4|^8.0`

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

[](#installation)

```
composer require amir-hossein5/laravel-image
```

and for publishing configuration file:

```
php artisan vendor:publish --tag image
```

And finally you may specify your sizes in configuration:

```
'use_size' => 'imageSizes',

 'imageSizes' => [
    'large' => [
        'width' => '800',
        'height' => '600'
    ],
    'medium' => [
        'width' => '400',
        'height' => '300'
    ],
    'small' => [
        'width' => '80',
        'height' => '60'
    ]
],

```

"make" method
-------------

[](#make-method)

In `make` method defaults for directories(archive path(2021/12/2)) and sizes will be set. Beacause of this, when you use:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::make($request->image) // or pass **Intervention object**
  ->setExclusiveDirectory('post')
  ->save();
```

saves in:

- `public/`
    - `images/post/2021/12/2/1638611107/`
        - `1638611107_960_large.png`
        - `1638611107_960_medium.png`
        - `1638611107_960_small.png`

It will create your image in archive path(2021/12/2), and with those sizes, that you defined in config (in `use_size` part). But how to customize directories, and sizes.

For size customazations see [Size customazations](#size-customazations).

### Directory customazations

[](#directory-customazations)

In parantheses written name of each directory:

- `images(rootDirectory)`
- `/post(exclusiveDirectory)`
- `/2021/12/2/(archiveDirectories)`
- `/1638611107(sizesDirectory)` -&gt; **if there be more than one size**

Image path setters:

setterdefaultsetImageName( string )time()\_rand(100, 999)\_sizeName(if there be any size)setImageFormat( string )uploaded image format. e.g, `->setImageFormat('png')`be( string )sets both image name and format. e.g, `->be('name.png')`setSizesDirectory( string )time()Just available for `make`:

setterdefaultsetRootDirectory( string )images (written in config file)setExclusiveDirectory( string )setArchiveDirectories( string )year/month/day> Notice: root directory is also changeable in config file.

Example:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::make($image)
  ->setExclusiveDirectory('book')
  ->setRootDirectory('image')
  .
  .
  .
  ->save()
```

For size customazations see [Size customazations](#size-customazations).

"raw" method
------------

[](#raw-method)

When you are using "raw" method,

nothing will be automatically set(archive path(2021/12/2), and sizes). For setting directory of image:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::raw($image) // or pass **Intervention object**
  ->in('book')
  ->save()

// without resizing
// will be save in public/book/

Image::raw($image)->save()

// without resizing
// will be save in public/
```

For add size, and size customazations see [Size customazations](#size-customazations).

Save in storage
---------------

[](#save-in-storage)

For saving into storage folder you can use disks, which defined in config:

```
'disks' => [
    'public' => public_path(),
    'storage' => storage_path('app')
]
```

By default it's `public`.

```
use AmirHossein5\LaravelImage\Facades\Image;

$images = Image::make($image)
  ->setExclusiveDirectory('post')
  ->disk('storage')
  ->save();
```

Will be:

- `storage/app/`
    - `images/post/2021/12/2/1638611107/`
        - `1638611107_960_large.png`
        - `1638611107_960_medium.png`
        - `1638611107_960_small.png`

You may add more disks and use from that.

Size customazations
-------------------

[](#size-customazations)

Size setters:

setterdescriptionautoResize()removes previous defined sizesresize( $width, $height, $as = null )removes previous defined sizes, and adds a sizealsoResize( $width, $height, $as = null )adds a sizeresizeBy( array )resize by intended array(the structure shuold be like 'imageSizes' in configuration)> For automatically resizing use `make` method and define sizes in config file (in `use_size` part).

### Default size

[](#default-size)

If you want to use default\_size functionality, you may define it in config file, or after image was created:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::setDefaultSizeFor($post->image, 'small');
```

Will return previous array but default\_size has changed or added.

Result array
------------

[](#result-array)

After creating image if operation was successful, it returns array, which

`index` key is array,or string(contains one, or more) image paths, which depends on number of sizes.

For example:

```
[
  "index" => [
      "images/post/2021/12/08/1638966454/1638966454_491_large.png",
      "images/post/2021/12/08/1638966454/1638966454_491_meduim.png",
      "images/post/2021/12/08/1638966454/1638966454_491_small.png",
   ]
   // or
   "index" => "image path"

   "imageDirectory" =>  "images/post/2021/12/08/1638966454"
   "default_size" => 'medium'
   "disk" => 'public'
]
```

> `default_size` key when you are using "default\_size", and there are **more than one size**, will be.

### Getting result array manually

[](#getting-result-array-manually)

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::make($this->image)
  ->setExclusiveDirectory('post')
  ->save(false, function ($image) {
    return [
      'index' => $image->imagePath,
      'imageDirectory' => $image->imageDirectory,
      'disk' => $image->disk,
    ];
  });
```

output:

```
[
  "index" => [
      "images/post/2021/12/08/1638966454/1638966454_491_large.png",
      "images/post/2021/12/08/1638966454/1638966454_491_meduim.png",
      "images/post/2021/12/08/1638966454/1638966454_491_small.png",
   ]
   // or
   "index" => "images/post/2021/12/08/1638966454/"

   "imageDirectory" => "images/post/2021/12/08/1638966454"
   "disk" => 'public'
]

```

Properties:

PropertyDescription$image-&gt;imageUploaded image object.$image-&gt;sizesAll used sizes.$image-&gt;defaultSizeDefault size.$image-&gt;imagePathFull path of stored image(s).$image-&gt;imageDirectoryImage's directory.$image-&gt;imageNameImage name.$image-&gt;imageFormatImage format.$image-&gt;disk[Disk](#save-in-storage)$image-&gt;quality[Image Quality](#image-quality)$image-&gt;rootDirectory[see Directory customazations](#directory-customazations)$image-&gt;exclusiveDirectory[see Directory customazations](#directory-customazations)$image-&gt;archiveDirectories[see Directory customazations](#directory-customazations)$image-&gt;sizesDirectory[see Directory customazations](#directory-customazations)Upsize or not
-------------

[](#upsize-or-not)

If you want to use upsize of intervention you should:

```
  ->save(true)
```

Removeing image(s)
------------------

[](#removeing-images)

Pass created image:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::rm($post->image);
```

which returns `true` or `false`.

If you created your result array **manually** pass the key of array, which there is image path(s):

```
use AmirHossein5\LaravelImage\Facades\Image;

$image = Image::make($this->image)
  ->setExclusiveDirectory('post')
  ->save(false, function ($image) {
    return ['paths' => $image->imagePath];
  });

Image::rm($image, 'paths');
```

Or if it's one string path just pass it:

```
use AmirHossein5\LaravelImage\Facades\Image;

$image = Image::raw($this->image)
  ->in('post/test')
  ->save(false, function ($image) {
    return $image->imagePath;
  });

Image::rm($image);
```

to check that is removed, or not:

```
use AmirHossein5\LaravelImage\Facades\Image;

if (! Image::rm($image)) {
  // ...
}
```

```
use AmirHossein5\LaravelImage\Facades\Image;

if (! Image::wasRecentlyRemoved()) {
  // ...
}
```

#### Remove when used disk

[](#remove-when-used-disk)

If you created image with some disks do:

```
use AmirHossein5\LaravelImage\Facades\Image;

....
  ->disk('storage')
....

Image::disk('storage')->rm($image);
```

Replacing image(s)
------------------

[](#replacing-images)

`replace` method works same as `save` method, but if there be image(s) with same name as this image, this will be replace.

```
use AmirHossein5\LaravelImage\Facades\Image;

$image = Image::raw($this->image)
    ->be('logo.png')
    ->replace();
```

It works for multipe images too.

Image Quality
-------------

[](#image-quality)

It is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file). Quality is only applied if you're encoding JPG format since PNG compression is lossless and does not affect image quality. The default value is 90.

```
  ->quality(90)
```

Transactions
------------

[](#transactions)

If an exception is thrown within the transaction closure, the transaction will automatically be rolled back and the exception is re-thrown. If the closure executes successfully, the transaction will automatically be committed.

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::transaction(function () {
  Image::raw($image)->save();
});
```

### Max Attempts

[](#max-attempts)

The `transaction` method accepts an optional second argument which defines the number of times a transaction should be retried when a deadlock occurs.

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::transaction(function () {
  Image::raw($image)->save();
}, maxAttempts: 4);
```

### Manually Using Transactions

[](#manually-using-transactions)

For begin transaction manually:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::beginTransaction();
```

You can rollback the transaction via the `rollBack` method:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::rollBack();
```

Lastly, you can commit a transaction via the `commit` method:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::commit();
```

Testing
-------

[](#testing)

If you don't want to image be ceate use fake before your code:

```
use AmirHossein5\LaravelImage\Facades\Image;

Image::fake();

Image:: ...
```

Examples
--------

[](#examples)

```
use AmirHossein5\LaravelImage\Facades\Image;

$request['image'] = Image::make($request['image'])
  ->setExclusiveDirectory('post')
  ->save();

if (!$request['image']) {
  return back()
    ->withInput()
    ->withErrors(['image' => __('validation.uploaded')]);
}

Post::create($request);
```

```
use AmirHossein5\LaravelImage\Facades\Image;

if(!Image::rm($post->image)){
  return back()->with('fail message');
}

$post->delete;
```

```
use AmirHossein5\LaravelImage\Facades\Image;

$image = Image::setDefaultSizeFor($post->image, $request['default_size']);

if (!$image) {
  return back()
    ->withInput()
    ->withErrors(['image' => __('validation.uploaded')]);
}

$post->image = $image;
$post->save();
```

```
use AmirHossein5\LaravelImage\Facades\Image;

$request['icon'] = Image::raw($request['icon'])
    ->be('icon.png')
    ->replace(false, function ($image) {
        return $image->imagePath;
    });

if (!$request['icon']) {
  return back()
    ->withInput()
    ->withErrors(['image' => __('validation.uploaded')]);
}
```

```
use AmirHossein5\LaravelImage\Facades\Image;

$img = Intervention::make('https://avatars.githubusercontent.com/u/68776630?s=40&v=4');

$avatar = Image::raw($img)
    ->in('avatar')
    ->save();
```

License
-------

[](#license)

[License](LICENSE)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 96.6% 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 ~18 days

Recently: every ~28 days

Total

11

Last Release

1424d ago

Major Versions

1.x-dev → v2.0.02022-01-12

PHP version history (2 changes)v1.0.0PHP &gt;=7.4

v2.1.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8965321404f59b9bc2b2ec90f25cc2dd341030cb6863de0d4721a12b239ae079?d=identicon)[amirHossein5](/maintainers/amirHossein5)

---

Top Contributors

[![amirHossein5](https://avatars.githubusercontent.com/u/68776630?v=4)](https://github.com/amirHossein5 "amirHossein5 (114 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (4 commits)")

---

Tags

interventionlaravelphpresize-images

### Embed Badge

![Health badge](/badges/amir-hossein5-laravel-image/health.svg)

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

###  Alternatives

[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[justbetter/statamic-image-optimize

Image optimization after upload

1315.2k](/packages/justbetter-statamic-image-optimize)

PHPackages © 2026

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