cache — Create cached images

Description

public static Intervention\Image\Image cache(Closure $callback, [int $lifetime, [bool $returnObj]])

Static factory method to create a new cached image instance from a Closure callback. Pass a lifetime in minutes for the callback and decide whether you want to get an Intervention Image instance as return value or just receive the image stream.

Note: This method requires the additional package intervention/imagecache.

Parameters

callback

A closure containing the operations on an image, defining the cached image.

lifetime (optional)

The lifetime in minutes of the image callback in the cache. (Default: 5)

returnObj (optional)

Decide if you want the method to return an Intervention Image instance or (by default) the image stream.

Return Values

Mixed - based on returnObj parameter.

Examples

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

See also