Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrtimofey/laravel-aio-images
All-in-one Laravel/Lumen image processing
https://github.com/mrtimofey/laravel-aio-images
database database-migrations eloquent image image-manipulation image-processing imagemagick images laravel laravel-5-package laravel-package laravel5 lumen model
Last synced: 2 months ago
JSON representation
All-in-one Laravel/Lumen image processing
- Host: GitHub
- URL: https://github.com/mrtimofey/laravel-aio-images
- Owner: mrTimofey
- License: mit
- Created: 2017-11-13T09:43:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-02T15:04:24.000Z (over 4 years ago)
- Last Synced: 2024-10-09T16:21:52.180Z (3 months ago)
- Topics: database, database-migrations, eloquent, image, image-manipulation, image-processing, imagemagick, images, laravel, laravel-5-package, laravel-package, laravel5, lumen, model
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# All-in-one Laravel image processing
This package includes the following:
* images database table migration;
* images Eloquent model;
* controller for uploads and on-the-fly/on-demand image processing/caching;
* service provider.Any uploaded or generated image is automatically optimized using the
[spatie/image-optimizer](https://github.com/spatie/image-optimizer) package.On-the-fly image generation just uses [intervention/image](http://image.intervention.io/) package.
## Requirements
* PHP 7.1
* Laravel or Lumen 5## Installation
```bash
sudo apt-get install pngquant gifsicle jpegoptim optipng
composer require mr-timofey/laravel-aio-images
```### Laravel
```bash
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
php artisan vendor:publish --provider="MrTimofey\LaravelAioImages\ServiceProvider"
php artisan migrate
```**Migration will create the `aio_images` table which contains a `json` field `props`.
You can change it to `text` if your database does not support JSON/JSONB fields.
Although it is not recommended.**If you want to use `storage/app/public` as a place to store all your images (configured by default):
```bash
php artisan storage:link
```**For Laravel <= 5.4** add
`Intervention\Image\ImageServiceProvider`,
`MrTimofey\LaravelAioImages\ServiceProvider`
to your `app.providers` config.See `config/aio_images.php` file for a further configuration instructions.
**Do not forget to configure `aio_images.pipes`!**### Lumen
Add `Intervention\Image\ImageServiceProviderLumen`, `MrTimofey\LaravelAioImages\ServiceProvider`
service providers to `bootstrap/app.php`.Copy contents of
[config.php](https://raw.githubusercontent.com/mrTimofey/laravel-aio-images/master/config.php)
to `config/aio_images.php`.Create a migration `php artisan make:migration create_aio_images_table` and copy contents
from [here](https://raw.githubusercontent.com/mrTimofey/laravel-aio-images/master/migrations/2000_01_01_000000_create_aio_images_table.php)
to the just created migration file (`database/migrations/xxxx_xx_xx_xxxxxx_create_aio_images_table`).See `config/aio_images.php` file for a further configuration instructions.
**Do not forget to configure `aio_images.pipes`!**## Predefined routes
* `route('aio_images.upload')`, `POST multipart/form-data` - image uploads handler.
Both multiple and single image uploads are supported.
Field names does not matter since the controller just uses `Illuminate\Http\Request@allFiles()` to get your uploads.
* `route('aio_images.original', $image_id)` - original image path.
* `route('aio_images.pipe', [$pipe, $image_id])` - processed image path.## Usage example:
```php
// add relation to a table
/** @var Illuminate\Database\Schema\Blueprint $table */
$table->string('avatar_image_id')->nullable();
$table->foreign('avatar_image_id')
->references('id')
->on('aio_images')
->onDelete('set null');// add relation to a model
public function avatarImage()
{
$model->belongsTo(ImageModel::class, 'avatar_image_id');
}// create pipe config in config/aio_images.php
[
// ...
'pipes' => [
// /storage/images/avatar/image-id.jpg
'avatar' => [
// $interventionImage->fit(120)
['fit', 120],
// $interventionImage->greyscale()
['greyscale']
]
]
];// display original avatar
echo '';
// display 120x120 squared grey colored avatar
echo '';// same with ImageModel instance
echo '';
echo '';// upload image manually from any of your custom controllers
use Illuminate\Http\Request;
use MrTimofey\LaravelAioImages\ImageModel;function upload(Request $req)
{
return ImageModel::upload($req->file('image'));
}```