2017 © Pedro Peláez
 

library images

image

lifeentity/images

  • Sunday, September 28, 2014
  • by kareem3d
  • Repository
  • 0 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Image generation and caching in Laravel

This Laravel 4 package provides an easy way to generate and cache images on the fly, (*1)

Installation

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)

  • your images directory
  • the base path
  • the cache directory name

Usage

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)

The Versions

28/09 2014

dev-master

9999999-dev

  Sources   Download

The Requires

 

by Kareem Mohamed