PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 2.8.17 2.8.18 All 259 releases
wpfunnels / vendor / intervention / image / src / Intervention / Image / ImageManager.php

ImageManager.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.1, at vendor/intervention/image/src/Intervention/Image/ImageManager.php

143 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Intervention\Image;
4
5 use Closure;
6 use Intervention\Image\Exception\MissingDependencyException;
7 use Intervention\Image\Exception\NotSupportedException;
8
9 class ImageManager
10 {
11 /**
12 * Config
13 *
14 * @var array
15 */
16 public $config = [
17 'driver' => 'gd'
18 ];
19
20 /**
21 * Creates new instance of Image Manager
22 *
23 * @param array $config
24 */
25 public function __construct(array $config = [])
26 {
27 $this->checkRequirements();
28 $this->configure($config);
29 }
30
31 /**
32 * Overrides configuration settings
33 *
34 * @param array $config
35 *
36 * @return self
37 */
38 public function configure(array $config = [])
39 {
40 $this->config = array_replace($this->config, $config);
41
42 return $this;
43 }
44
45 /**
46 * Initiates an Image instance from different input types
47 *
48 * @param mixed $data
49 *
50 * @return \Intervention\Image\Image
51 */
52 public function make($data)
53 {
54 return $this->createDriver()->init($data);
55 }
56
57 /**
58 * Creates an empty image canvas
59 *
60 * @param int $width
61 * @param int $height
62 * @param mixed $background
63 *
64 * @return \Intervention\Image\Image
65 */
66 public function canvas($width, $height, $background = null)
67 {
68 return $this->createDriver()->newImage($width, $height, $background);
69 }
70
71 /**
72 * Create new cached image and run callback
73 * (requires additional package intervention/imagecache)
74 *
75 * @param Closure $callback
76 * @param int $lifetime
77 * @param boolean $returnObj
78 *
79 * @return Image
80 */
81 public function cache(Closure $callback, $lifetime = null, $returnObj = false)
82 {
83 if (class_exists('Intervention\\Image\\ImageCache')) {
84 // create imagecache
85 $imagecache = new ImageCache($this);
86
87 // run callback
88 if (is_callable($callback)) {
89 $callback($imagecache);
90 }
91
92 return $imagecache->get($lifetime, $returnObj);
93 }
94
95 throw new MissingDependencyException(
96 "Please install package intervention/imagecache before running this function."
97 );
98 }
99
100 /**
101 * Creates a driver instance according to config settings
102 *
103 * @return \Intervention\Image\AbstractDriver
104 */
105 private function createDriver()
106 {
107 if (is_string($this->config['driver'])) {
108 $drivername = ucfirst($this->config['driver']);
109 $driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername);
110
111 if (class_exists($driverclass)) {
112 return new $driverclass;
113 }
114
115 throw new NotSupportedException(
116 "Driver ({$drivername}) could not be instantiated."
117 );
118 }
119
120 if ($this->config['driver'] instanceof AbstractDriver) {
121 return $this->config['driver'];
122 }
123
124 throw new NotSupportedException(
125 "Unknown driver type."
126 );
127 }
128
129 /**
130 * Check if all requirements are available
131 *
132 * @return void
133 */
134 private function checkRequirements()
135 {
136 if ( ! function_exists('finfo_buffer')) {
137 throw new MissingDependencyException(
138 "PHP Fileinfo extension must be installed/enabled to use Intervention Image."
139 );
140 }
141 }
142 }
143