dev-master
9999999-dev
The Requires
- php >=5.3.0
- intervention/image 2.*
- illuminate/support 4.2.*
by Kareem Mohamed
Wallogit.com
2017 © Pedro Peláez
This Laravel 4 package provides an easy way to generate and cache images on the fly, (*1)
Begin by installing this package through Composer. Edit your project's composer.json file to require lifeentity/images., (*2)
"require": {
"lifeentity/images": "2.*"
}
Next, update Composer from the Terminal:, (*3)
composer update
Once this operation completes, the final step is to add the service provider. Open app/config/app.php, and add a new item to the providers array., (*4)
'Lifeentity\Images\ImagesServiceProvider'
Next, run this migrate command to create the images table (don't forget to configure your database), (*5)
php artisan migrate --package=lifeentity/images
Optional step, run this artisan command to publish the config file, (*6)
php artisan config:publish lifeentity/images
The config file contains information about:, (*7)
Attach any of your models to the image eloquent model., (*8)
<?php
use Lifeentity\Images\ImageDB;
class Product {
// ...
protected function images() {
return $this->morphMany('Lifeentity\Images\ImageDB', 'imageable');
}
}
Create new image and save it to the product, (*9)
<?php
// Create a new image and attach it to a product
$image = new ImageDB(array(
'path' => '/images/path/to/image/image.jpg'
));
Product::find(1)->image()->save($image);
Display product original image and resized version of the image, (*10)
<?php
$image = Product::find(1);
echo '<img src="'.$image->original_url.'" />';
// Resize image before displaying to the user
echo '<img src="'.$image->addOperation('resize', 300, null, true)->cached_url.'" />';
Want to make complex operations on the image? Register an image filter, (*11)
<?php
// Register new operation
App::make('Lifeentity\Images\ImageFilter')->register('watermark.v1', function(Intervention\Image\Image $image)
{
// If you want you can add this facade to the aliases in the app.php config file
$watermark = \Intervention\Image\Facades\Image::make(public_path('/images/watermark.jpg'));
// For a list of operations you can do on an image please refer to intervention image package bellow
$watermark->resize(0.4 * $image->getWidth(), null, function($constraints)
{
$constraints->aspectRatio();
});
$image->insert($watermark, 'bottom-right');
});
This package depends on intervention/image v2.*. For list of operations you can do on images follow this link Intervention Image, (*12)