Cheetah
ImageManager.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Intervention\Image;
4 
5 use Closure;
6 
8 {
14  public $config = array(
15  'driver' => 'gd'
16  );
17 
23  public function __construct(array $config = array())
24  {
25  $this->checkRequirements();
26  $this->configure($config);
27  }
28 
34  public function configure(array $config = array())
35  {
36  $this->config = array_replace($this->config, $config);
37 
38  return $this;
39  }
40 
48  public function make($data)
49  {
50  return $this->createDriver()->init($data);
51  }
52 
62  public function canvas($width, $height, $background = null)
63  {
64  return $this->createDriver()->newImage($width, $height, $background);
65  }
66 
77  public function cache(Closure $callback, $lifetime = null, $returnObj = false)
78  {
79  if (class_exists('Intervention\\Image\\ImageCache')) {
80  // create imagecache
81  $imagecache = new ImageCache($this);
82 
83  // run callback
84  if (is_callable($callback)) {
85  $callback($imagecache);
86  }
87 
88  return $imagecache->get($lifetime, $returnObj);
89  }
90 
91  throw new \Intervention\Image\Exception\MissingDependencyException(
92  "Please install package intervention/imagecache before running this function."
93  );
94  }
95 
101  private function createDriver()
102  {
103  $drivername = ucfirst($this->config['driver']);
104  $driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername);
105 
106  if (class_exists($driverclass)) {
107  return new $driverclass;
108  }
109 
110  throw new \Intervention\Image\Exception\NotSupportedException(
111  "Driver ({$drivername}) could not be instantiated."
112  );
113  }
114 
120  private function checkRequirements()
121  {
122  if ( ! function_exists('finfo_buffer')) {
123  throw new \Intervention\Image\Exception\MissingDependencyException(
124  "PHP Fileinfo extension must be installed/enabled to use Intervention Image."
125  );
126  }
127  }
128 }
Intervention\Image\ImageManager\canvas
canvas($width, $height, $background=null)
Definition: ImageManager.php:62
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
php
Intervention\Image\ImageManager\configure
configure(array $config=array())
Definition: ImageManager.php:34
Intervention\Image\ImageManager\$config
$config
Definition: ImageManager.php:14
Intervention\Image\ImageManager\make
make($data)
Definition: ImageManager.php:48
Intervention\Image\ImageManager
Definition: ImageManager.php:8
Intervention\Image\ImageManager\cache
cache(Closure $callback, $lifetime=null, $returnObj=false)
Definition: ImageManager.php:77
Intervention\Image\ImageManager\__construct
__construct(array $config=array())
Definition: ImageManager.php:23
Intervention\Image
Definition: AbstractColor.php:3