PHPackages                             konnco/laravel-imagecast - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. konnco/laravel-imagecast

ActiveLibrary[File &amp; Storage](/categories/file-storage)

konnco/laravel-imagecast
========================

Make easier to store images into database

0.1.1(4y ago)33.7k[1 PRs](https://github.com/konnco/laravel-imagecast/pulls)MITPHPPHP ^7.4|^8.0|^9.0

Since Jun 27Pushed 4y ago1 watchersCompare

[ Source](https://github.com/konnco/laravel-imagecast)[ Packagist](https://packagist.org/packages/konnco/laravel-imagecast)[ Docs](https://github.com/konnco/laravel-imagecast)[ GitHub Sponsors](https://github.com/konnco)[ RSS](/packages/konnco-laravel-imagecast/feed)WikiDiscussions main Synced 3w ago

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

The Easier Way to Storing Image in Laravel
==========================================

[](#the-easier-way-to-storing-image-in-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b59959a3af3bd6e3a293536c04b019aee3b8ca333e376ccc3ee91d8c93717b6e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6f6e6e636f2f6c61726176656c2d696d616765636173742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/konnco/laravel-imagecast)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8d0387ae1876adc320c149d94c46baef120fc6c2c99e3d7a08e154bc41dfed2c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6b6f6e6e636f2f6c61726176656c2d696d616765636173742f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/konnco/laravel-imagecast/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a417fa869aaad8935e14aca651f4264d181364b2d2c1368b6d1edb043820b5b3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6b6f6e6e636f2f6c61726176656c2d696d616765636173742f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/konnco/laravel-imagecast/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/935f7f26da4af401e9ffd1c919943d59a805c900a53e6344b8266a8f68e894c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6f6e6e636f2f6c61726176656c2d696d616765636173742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/konnco/laravel-imagecast)

This package is designed to simplify our code for managing the laravel image.

Alpha Version
-------------

[](#alpha-version)

Attention! This package is still under development, we still looking the best pattern we can apply, and in the way, the development may break your application, we would not recommended you using to use this application on production until this package is fully released.

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

[](#installation)

### Laravel Version

[](#laravel-version)

TagsLaravel Version0.0.7Laravel 80.1.0Laravel 9You can install the package via composer:

```
composer require konnco/laravel-imagecast
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Konnco\ImageCast\ImageCastServiceProvider" --tag="laravel-imagecast-config"
```

This is the contents of the published config file:

```
return [
    'disk' => env('IMAGECAST_DISK', 'public'),
    'path' => 'images',
    'blurhash' => env('IMAGECAST_BLURHASH', false)
];
```

Usage
-----

[](#usage)

Easy! just apply the `Image` into the image type attribute, example :

import these file

```
use Konnco\ImageCast\Casts\Image;
```

and implement it like this

```
protected $casts = [
    'avatar' => Image::class,
];
```

Also you can applying custom configuration for each field, example :

```
protected $casts = [
    'avatar' => Image::class.":80,images/account/avatar,jpg",
    'banner' => Image::class.":80,images/account/avatar,png",
];
```

with parameters `:quality,savePath,extension`. For the `savePath` variable you may want to insert random variable like date as the folder name, you can follow the example

```
protected $casts = [
    'avatar' => Image::class.":80,images/account/avatar/{date:Y-m-d},jpg",
];
```

After defining all of those configuration you can start uploading the image, example :

```
$user = New User();
$user->name = $request->name;
$user->avatar = $request->photo;
$user->save();
```

you can fill the avatar fields with all of these supported type :

- string - Path of the image in filesystem.
- string - URL of an image (allow\_url\_fopen must be enabled).
- string - Binary image data.
- string - Data-URL encoded image data.
- string - Base64 encoded image data.
- resource - PHP resource of type gd. (when using GD driver)
- object - Imagick instance (when using Imagick driver)
- object - Intervention\\Image\\Image instance
- object - SplFileInfo instance (To handle Laravel file uploads via Symfony\\Component\\HttpFoundation\\File\\UploadedFile)

Url Generator
-------------

[](#url-generator)

With the ImageCast Url Generator you can define the image width and height only with the url, if you already get used with cloudinary, you will thank this package.

We should configure the 404 handler for Laravel. Open `App\Exceptions\Handler` and and the code below inside the `render` method.

```
use Konnco\ImageCast\ImageCastExceptionHandler;

public function render($request, Throwable $exception) {
    return new ImageCastExceptionHandler($exception, request()->url(), function(){
        return parent::render($request, $exception);
    });
}
```

We already added the helpers inside the `ImageCast` and it can be defined like script below :

```
return $user->avatar->toUrl();
```

### Base64

[](#base64)

You can also convert your image to base64 image with this method

```
return $user->avatar->toBase64();
```

Idea
----

[](#idea)

We really appreciate your idea and contribution into this package :)

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Franky So](https://github.com/konnco)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Recently: every ~50 days

Total

9

Last Release

1588d ago

PHP version history (2 changes)0.0.1PHP ^7.4|^8.0

0.1.0PHP ^7.4|^8.0|^9.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2cc4521e9641c59a269f7ec3a670d781681e7d7be8e57be66dafd95d15304693?d=identicon)[frankyso.pg](/maintainers/frankyso.pg)

---

Top Contributors

[![frankyso](https://avatars.githubusercontent.com/u/5705520?v=4)](https://github.com/frankyso "frankyso (52 commits)")

---

Tags

laravelkonncolaravel-imagecast

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/konnco-laravel-imagecast/health.svg)

```
[![Health](https://phpackages.com/badges/konnco-laravel-imagecast/health.svg)](https://phpackages.com/packages/konnco-laravel-imagecast)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M42](/packages/spatie-laravel-pdf)[spatie/laravel-health

Monitor the health of a Laravel application

87411.3M153](/packages/spatie-laravel-health)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

43140.3k](/packages/harris21-laravel-fuse)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24855.3k](/packages/vormkracht10-laravel-mails)[danihidayatx/image-optimizer

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

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

PHPackages © 2026

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