2017 © Pedro Peláez
 

library laravel-aio-images

All-in-one Laravel image processing

image

mr-timofey/laravel-aio-images

All-in-one Laravel image processing

  • Monday, June 4, 2018
  • by mrTimofey
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,201 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 38 % Grown

The README.md

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., (*1)

Any uploaded or generated image is automatically optimized using the spatie/image-optimizer package., (*2)

On-the-fly image generation just uses intervention/image package., (*3)

Requirements

  • PHP 7.1
  • Laravel or Lumen 5

Installation

sudo apt-get install pngquant gifsicle jpegoptim optipng
composer require mr-timofey/laravel-aio-images

Laravel

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., (*4)

If you want to use storage/app/public as a place to store all your images (configured by default):, (*5)

php artisan storage:link

For Laravel <= 5.4 add Intervention\Image\ImageServiceProvider, MrTimofey\LaravelAioImages\ServiceProvider to your app.providers config., (*6)

See config/aio_images.php file for a further configuration instructions. Do not forget to configure aio_images.pipes!, (*7)

Lumen

Add Intervention\Image\ImageServiceProviderLumen, MrTimofey\LaravelAioImages\ServiceProvider service providers to bootstrap/app.php., (*8)

Copy contents of config.php to config/aio_images.php., (*9)

Create a migration php artisan make:migration create_aio_images_table and copy contents from here to the just created migration file (database/migrations/xxxx_xx_xx_xxxxxx_create_aio_images_table)., (*10)

See config/aio_images.php file for a further configuration instructions. Do not forget to configure aio_images.pipes!, (*11)

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:

// 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 '<img src="' . route('aio_images.original', ['image_id' => $model->avatar_image_id]) . '" alt="Original avatar" />';
// display 120x120 squared grey colored avatar
echo '<img src="' . route('aio_images.pipe', ['pipe' => 'avatar', 'image_id' => $model->avatar_image_id]) . '" alt="Processed with pipe [avatar]" />';

// same with ImageModel instance
echo '<img src="' . $image->getPath() . '" alt="Original avatar" />';
echo '<img src="' . $image->getPath('avatar') . '" alt="Processed with pipe [avatar]" />';


// 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'));
}

The Versions

04/06 2018

dev-master

9999999-dev

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

09/03 2018

0.2.3

0.2.3.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

06/03 2018

0.2.2

0.2.2.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

06/03 2018

0.2.1

0.2.1.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

06/03 2018

0.2.0

0.2.0.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

28/02 2018

0.1.4

0.1.4.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

07/02 2018

0.1.3

0.1.3.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

30/01 2018

0.1.2

0.1.2.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

29/01 2018

0.1.1

0.1.1.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

29/01 2018

0.1.0

0.1.0.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

02/12 2017

0.0.6

0.0.6.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

02/12 2017

0.0.5

0.0.5.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

01/12 2017

0.0.4

0.0.4.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

01/12 2017

0.0.3

0.0.3.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

29/11 2017

0.0.2

0.0.2.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale

29/11 2017

0.0.1

0.0.1.0

All-in-one Laravel image processing

  Sources   Download

MIT

The Requires

 

by Timofey

laravel image resize gd imagick thumbnail watermark optimize greyscale