Code Monkey home page Code Monkey logo

imagecache's Introduction

Intervention Image Cache

Intervention Image Cache extends the Intervention Image Class package to be capable of image caching functionality.

The library uses the Illuminate/Cache package and can be easily integrated into the Laravel Framework. Based on your Laravel cache configuration you are able to choose between Filesystem, Database, Memcached or Redis for the temporary buffer store.

The principle is simple. Every method call to the Intervention Image class is captured and checked by the caching interface. If this particular sequence of operations already have taken place, the data will be loaded directly from the cache instead of a resource-intensive image operation.

Installation

You can install this package quickly and easily with Composer.

Require the package via Composer:

$ composer require intervention/imagecache

Now you are able to require the vendor/autoload.php file to PSR-4 autoload the library.

Laravel Integration

The Image Cache class supports Laravel integration. Best practice to use the library in Laravel is to add the ServiceProvider and Facade of the Intervention Image Class.

Open your Laravel config file config/app.php and add the following lines.

In the $providers array add the service providers for this package.

'providers' => array(
    
    [...]

    'Intervention\Image\ImageServiceProvider'
),

Add the facade of this package to the $aliases array.

'aliases' => array(
    
    [...]

    'Image' => 'Intervention\Image\Facades\Image'
),

Usage

The Image Cache is best called by the static method Image::cache from the Intervention Image class.

To create cached images just use the static method Image::cache and pass the image manipulations via closure. The method will automatically detect if a cached file for your particular operations exists.

// run the operations on the image or read a file
// for the particular operations from cache
$img = Image::cache(function($image) {
   return $image->make('public/foo.jpg')->resize(300, 200)->greyscale();
});

Determine a lifetime in minutes for the cache file as an optional second parameter. Pass a boolean true as optional third parameter to return an Intervention Image object instead of a image stream.

// determine a lifetime and return as object instead of string
$img = Image::cache(function($image) {
   return $image->make('public/foo.jpg')->resize(300, 200)->greyscale();
}, 10, true);

License

Intervention Imagecache Class is licensed under the MIT License.

imagecache's People

Contributors

olivervogel avatar riesjart avatar pyrello avatar gluxon avatar

Watchers

James Cloos avatar  avatar

Forkers

alishiwani

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.