1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-21 05:01:20 +02:00

added cache method

This commit is contained in:
Oliver Vogel
2014-05-16 19:39:59 +02:00
parent 8cc16b4728
commit b0786aecf8

View File

@@ -81,4 +81,29 @@ class ImageManager
{ {
return $this->createDriver()->newImage($width, $height, $background); return $this->createDriver()->newImage($width, $height, $background);
} }
/**
* Create new cached image and run callback
* (requires additional package intervention/imagecache)
*
* @param Closure $callback
* @param integer $lifetime
* @param boolean $returnObj
*
* @return Image
*/
public function cache(Closure $callback, $lifetime = null, $returnObj = false)
{
if (class_exists('\Intervention\Image\ImageCache')) {
// Create imagecache and run callback
$imagecache = new ImageCache($this);
$imagecache = is_callable($callback) ? $callback($imagecache) : $imagecache;
return $imagecache->get($lifetime, $returnObj);
}
throw new \Intervention\Image\Exception\NotSupportedException(
"Please install package intervention/imagecache before running this function."
);
}
} }