PHPackages                             takshak/imager - 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. takshak/imager

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

takshak/imager
==============

Imager provider package for laravel

1.5.1(1y ago)01.5k2MITPHP

Since Jan 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/takshaktiwari/imager)[ Packagist](https://packagist.org/packages/takshak/imager)[ RSS](/packages/takshak-imager/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (1)Versions (16)Used By (2)

Introduction
============

[](#introduction)

This package gives you three different tools, which are useful to fake, seed, generate placeholders and manipulate images. These tools are named as Picsum (provides images to seed database, or helps in creating model factories), Placeholder (generates placeholder images for specific location in different sizes and colors), Imager (manipulates images in desired sizes, can be used to resize an image if you don't want to cut any of edge of the images). These manipulations can be also called from the URL.

Quick Start
-----------

[](#quick-start)

Install the package with composer

```
composer require takshak/imager

```

Simple uses

```
use Takshak\Imager\Facades\Picsum;
use Takshak\Imager\Facades\Placeholder;
use Takshak\Imager\Facades\Imager;

Picsum::dimensions(500, 500)->response();

Placeholder::dimensions(500, 500)->text('Some Info Text')->response();

Imager::init($request->file('image_file'))->resizeFit(500, 500)->response();

```

User can also use directly with the respective aliases without using the class name at the top. eg:

```
\Picsum::dimensions(500, 500)->response();

\Placeholder::dimensions(500, 500)->text('Some Info Text')->response();

\Imager::init($request->file('image_file'))->resizeFit(500, 500)->response();

```

Placeholder (Dummy / Avatar image provider)
-------------------------------------------

[](#placeholder-dummy--avatar-image-provider)

You can have some fake images of may be some placeholder images with specified dimensions, having some written text and also in different colours. You can also generate user avatars also. Image can be further resized, saved to folder and also can be saved to model.

**`background($hexColor):`** Set the color of image background

**`image($width=null, $height=null, $background=null):`** Instantiate the image if image is not already generated all the parameters are optional

**`text($text='Placeholder Image', $format=[]):`** Write text on the image and format the text as well. Possible format array keys are: size, color, align, valign, angle. Eg.

```
\Placeholder::dimensions(500, 500)
    ->text('dummy text', [
        'size'  =>  50,
        'color' =>  '#000',
        'align' =>  'center',
        'valign'    =>  'center',
        'angle'     =>  45
    ])
    ->response();

```

**`url():`** Generates the local URL for given type of image. Specified image can be also called by this URL

For all other functions please refer to [common methods](https://github.com/takshaktiwari/imager#common-methods)

Default values: `$width = 500;` `$height = 500;` `$background = '#ccc';` `$extension = 'jpg';` `$textFormating = [ 'size'   =>  24, 'color' =>  '#000', 'align' =>  'center', 'valign'  =>  'center', 'angle'       =>  null ];`

### Generating placeholder image from URL

[](#generating-placeholder-image-from-url)

Base URL: `http://project.com/imgr/placeholder?paramters`

ParameterDefaultDescriptionwidth / w1000Width of imageheight / h1000Height of imagebackground / bg'ccc'Set the backgroundextension / ext'jpg'Image formattextText on imagetext\_colorColor of text (if text parameter available)text\_size24Size of the text (if text parameter available)text\_angleImage rotation angle (if text parameter available)text\_aligncenterText alignment (if text parameter available)text\_valigncenterVertical alignment (if text parameter available)blur1Blur image, pass the blur amountgreyscaleMake image greyscale (pass the boolean as 0 or 1)flipFlip the image. Possible values: v / hrotateRotates image (angle of rotation in numeric)Sample image URL: `http://project.com/imgr/placeholder?w=150&h=150&text=JD&text_size=60&background=c00c0c`

Picsum (Fake image provider)
----------------------------

[](#picsum-fake-image-provider)

It provides some images to fake database or can used as placeholder. This stores some images to it's bucket and then returns randomly generated images as requested. Functions and default parameters are given below:

**`bucket($foldername):`** Name of source folder from where the images will be faked. If not setted default 'imgr-bucket' folder will be used.

**`disk($disk='local'):`** Storage disk name

**`seed(int: $count=10):`** Seed the bucket with some dummy images

**`flush():`** Flush all the images from bucket

**`refresh(int: $count=10):`** Flush all the images from bucket and seed new images

**`isEmpty():`** Checks if the bucket is empty

**`url():`** Generates the local URL for given type of image. Specified image can be also called by this URL

**`image():`** Instantiate the image if image is not already generated

For all other functions please refer to [common methods](https://github.com/takshaktiwari/imager#common-methods)

### Seeding images to the bucket

[](#seeding-images-to-the-bucket)

To seed / write some images (to be served when you request for better performance of picsum) execute following command

```
php artisan imager:seed

```

This can also receive several argument and options:

**arguments:**

> - `count`: number of images to be seeded (default '50')

**options:**

> - `--disk`: storage disk type (default 'local')
> - `--bucket`: this is the folder name where the images will be kept (default 'imgr-bucket/')
> - `--action`: action of the command. possible values are, seed, refresh, flush (default 'seed')
> - `--width`: width of the images to be seeded, (default '2000')
> - `--height`: height of the images to be seeded, (default '1500')

```
php artisan imager:seed 25

php artisan imager:seed 25 --width=1200 --height=800

```

### Generating picsum image from URL

[](#generating-picsum-image-from-url)

Base URL: `http://project.com/imgr/picsum?paramters`

ParameterDefaultDescriptionwidth / w1000Width of imageheight / h1000Height of imageextension / ext'jpg'Image formatrefresh10Flush all bucket image and seed new onesseed10Seed new imagesflushFlush all bucket imagesblur1Blur image, pass the blur amountgreyscaleMake image greyscale (pass the boolean as 0 or 1)flipFlip the image. Possible values: v / hrotateRotates image, (accepts integer, eg. ?rotage=45)Sample image URL: `http://project.com/imgr/picsum?w=150&h=150&blur=1&greyscale=1`

Imager (Easy image manipulation)
--------------------------------

[](#imager-easy-image-manipulation)

This can used to resize or fit an image within a dimensions or for other manipulations. This provides following methods:

**`init($image):`** Receives an image file / path / URL to work on

**`resizeHeight(int: $height):`** Defines the height of the image in pixels. (parameter optional if height() function has been already called)

**`resize(int: $width, int: $height):`** Defines the width and height of the image in pixels (image may squeeze or edges can be cropped). (parameters are optional if height(), width() or dimensions() function has been already called).

**`resizeFit(int: $width, int: $height):`** Defines the width and height of the image in pixels whichever fits the best, none of the edge will be cropped and image will never stretch. (parameters are optional if height(), width() or dimensions() function has been already called)

**`inCanvas($bg=null):`** If you want to generate image with any coloured background, eg. (#fff)

For all other functions please refer to [common methods](https://github.com/takshaktiwari/imager#common-methods)

Common Methods
--------------

[](#common-methods)

Following methods can be called to all above tools

**`width(int: $width):`** Define the width of image

**`height(int: $height):`** Define the height of image

**`dimensions(int: $dimensions):`** Width and height can be defined at once usin this function instead of *width()* and *height(*)

**`extension($extention):`** Extension of image, eg: 'png' or 'jpg'

**`response($extention=null):`** Returns the image as a response.

**`basePath($path):`** Set the base folder name where you want to store the image

**`save($path, $width=null):`** Save the path to any location. Width parameter is optional. Image will get resized were width will be passed

**`saveModel($model, $column, $filePath):`** Saves image path to the model.

**`blur(int: $amount=1):`** Blur the image

**`greyscale():`** Makes image grey scale

**`rotate(int: $deg=45):`** Rotates image on *$deg* degree

**`flip($direction='h'):`** Flips the image, possible values(v or h)

**`others(function($image){}):`** Passes the image through other function (intervention/image) for further manipulations.

**`destroy():`** Destroys the created image instance.

Placeholder - Some Uses
-----------------------

[](#placeholder---some-uses)

Getting Default dummy image

```
\Placeholder::text('Some Info Text')->response();

```

Customised Text in image

```
\Placeholder::text('Some Info Text', [
    'size'  =>  24,
    'color' =>  '#000',
    'align' =>  'center',
    'valign'    =>  'center',
    'angle'     =>  45
])->response();

```

Create dummy user avatar

```
\Placeholder::dimensions(200, 200)->text('JD')->response();

```

Save image to folder and model

```
\Placeholder::text('Some dummy text')
->basePath(\Storage::disk('local')->path('images'))
->save('image-lg.jpg')
->saveModel($user, 'profile_img', 'image-lg.jpg')
->save('image-md.jpg', 300)
->saveModel($user, 'profile_img', 'image-md.jpg')
->response();

```

Picsum - Some Uses
------------------

[](#picsum---some-uses)

Resize image during save

```
Picsum::dimensions(200, 200)->save(path:'path/image.jpg', 100);

```

Save at multiple locations

```
Picsum::dimensions(500, 500)
    ->save(path:'path/image.jpg')
    ->save(path:'path/image-md.jpg', 300)
    ->save(path:'path/image-sm.jpg', 100);

```

Get image URL

```
Picsum::dimensions(500, 500)->image()->url();

```

Save path to model

```
Picsum::dimensions(500, 500)
    ->save(path:'path/image.jpg')
    ->saveModel(User::first(), 'profime_img', path:'path/image.jpg');

```

Get URL for the image

```
Picsum::dimensions(500, 500)->url();

```

Other intervention callback function

```
$img = Picsum::image()->flip();
$img->others(function($img){
    $img->crop(100, 100);
});
return $img->response();

```

Save image to a model

```
$post = Post::first();
Picsum::dimensions(500, 500)
    ->save(path:'path/image.jpg')->saveModel($post, 'image_lg', path:'path/image.jpg')
    ->save(path:'path/image-sm.jpg', 100)->saveModel($post, 'image_sm', path:'path/image-sm.jpg')
    ->image(500, 400)
    ->save(path:'path/image.jpg')->saveModel(Post::find(2), 'image_lg', path:'path/image.jpg')
    ->url()

```

Imager - Some Uses
------------------

[](#imager---some-uses)

Saving three variants of the same image in `storage/app/public/images/... .jpg`

```
Imager::init($request->file('thumbnail'))
    ->resizeFit(800, 500)
    ->basePath(Storage::disk('public')->path('/'))
    ->save('images/large.jpg')
    ->save('images/medium.jpg', 400)
    ->save('images/small.jpg', 200);

# Or you can pass the path as follow
Imager::init($request->file('thumbnail'))
    ->resizeFit(800, 500)
    ->save(Storage::disk('public')->path('images/large.jpg'))
    ->save(Storage::disk('public')->path('images/medium.jpg'), 400)
    ->save(Storage::disk('public')->path('images/small.jpg'), 200);

```

Save image with a canvas of white(default) background and some extra manipulation:

```
Imager::init($request->file('thumbnail'))
    ->resizeFit(800, 500)->inCanvas('#fff') // resize to fit in given dimension
    ->inCanvas('#fff') // put the white canvas if image is shorter
    ->rotate(45)    // rotate image at 45 deg.
    ->flip('h')   // flip image horizontally (use 'v' for vertical flip)
    ->save(Storage::disk('public')->path('images/large.jpg')) // save the image
    ->save(Storage::disk('public')->path('images/medium.jpg'), 400) // save another with small size of 400

```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

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

Every ~74 days

Recently: every ~158 days

Total

15

Last Release

535d ago

### Community

Maintainers

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

---

Top Contributors

[![takshaktiwari](https://avatars.githubusercontent.com/u/58802422?v=4)](https://github.com/takshaktiwari "takshaktiwari (30 commits)")

### Embed Badge

![Health badge](/badges/takshak-imager/health.svg)

```
[![Health](https://phpackages.com/badges/takshak-imager/health.svg)](https://phpackages.com/packages/takshak-imager)
```

###  Alternatives

[league/glide

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

2.6k51.2M116](/packages/league-glide)[jenssegers/imagehash

Perceptual image hashing for PHP

2.1k2.2M5](/packages/jenssegers-imagehash)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M101](/packages/intervention-image-laravel)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[lasserafn/php-initial-avatar-generator

A package to generate avatars with initials for PHP

4374.2M13](/packages/lasserafn-php-initial-avatar-generator)[rtippin/messenger

Laravel messenger suite.

45035.8k4](/packages/rtippin-messenger)

PHPackages © 2026

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