Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
22 / 22 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
Image | |
100.00% |
22 / 22 |
|
100.00% |
10 / 10 |
13 | |
100.00% |
1 / 1 |
getAvailableAdapters | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
isAvailable | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
loadGd | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
loadImagick | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
loadGdFromString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
loadImagickFromString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createGd | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createGdIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createImagick | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createImagickIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Image; |
15 | |
16 | /** |
17 | * Image factory class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Image |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 4.0.0 |
25 | */ |
26 | class Image |
27 | { |
28 | |
29 | /** |
30 | * Get the available image adapters |
31 | * |
32 | * @return array |
33 | */ |
34 | public static function getAvailableAdapters(): array |
35 | { |
36 | return [ |
37 | 'gd' => function_exists('gd_info'), |
38 | 'imagick' => (class_exists('Imagick', false)) |
39 | ]; |
40 | } |
41 | |
42 | /** |
43 | * Determine if the adapter is available |
44 | * |
45 | * @param string $adapter |
46 | * @return bool |
47 | */ |
48 | public static function isAvailable(string $adapter): bool |
49 | { |
50 | $result = false; |
51 | |
52 | switch (strtolower($adapter)) { |
53 | case 'gd': |
54 | $result = function_exists('gd_info'); |
55 | break; |
56 | case 'imagemagick': |
57 | case 'imagick': |
58 | $result = (class_exists('Imagick', false)); |
59 | break; |
60 | } |
61 | |
62 | return $result; |
63 | } |
64 | |
65 | /** |
66 | * Load the image resource from the existing image file into a Gd object |
67 | * |
68 | * @param string $image |
69 | * @return Adapter\Gd |
70 | */ |
71 | public static function loadGd(string $image): Adapter\Gd |
72 | { |
73 | return Gd::load($image); |
74 | } |
75 | |
76 | /** |
77 | * Load the image resource from the existing image file into a Imagick object |
78 | * |
79 | * @param string $image |
80 | * @return Adapter\Imagick |
81 | */ |
82 | public static function loadImagick(string $image): Adapter\Imagick |
83 | { |
84 | return Imagick::load($image); |
85 | } |
86 | |
87 | /** |
88 | * Load the image resource from data into a Gd object |
89 | * |
90 | * @param string $data |
91 | * @param ?string $name |
92 | * @throws Adapter\Exception |
93 | * @return Adapter\Gd |
94 | */ |
95 | public static function loadGdFromString(string $data, ?string $name = null): Adapter\Gd |
96 | { |
97 | return Gd::loadFromString($data, $name); |
98 | } |
99 | |
100 | /** |
101 | * Load the image resource from data into a Imagick object |
102 | * |
103 | * @param string $data |
104 | * @param ?string $name |
105 | * @return Adapter\Imagick |
106 | */ |
107 | public static function loadImagickFromString(string $data, ?string $name = null): Adapter\Imagick |
108 | { |
109 | return Imagick::loadFromString($data, $name); |
110 | } |
111 | |
112 | /** |
113 | * Create a new image resource and load it into a Gd object |
114 | * |
115 | * @param int $width |
116 | * @param int $height |
117 | * @param ?string $image |
118 | * @return Adapter\Gd |
119 | */ |
120 | public static function createGd(int $width, int $height, ?string $image = null): Adapter\Gd |
121 | { |
122 | return Gd::create($width, $height, $image); |
123 | } |
124 | |
125 | /** |
126 | * Create a new indexed image resource and load it into a Gd object |
127 | * |
128 | * @param int $width |
129 | * @param int $height |
130 | * @param ?string $image |
131 | * @throws Adapter\Exception |
132 | * @return Adapter\Gd |
133 | */ |
134 | public static function createGdIndex(int $width, int $height, ?string $image = null): Adapter\Gd |
135 | { |
136 | return Gd::createIndex($width, $height, $image); |
137 | } |
138 | |
139 | /** |
140 | * Create a new image resource and load it into a Imagick object |
141 | * |
142 | * @param int $width |
143 | * @param int $height |
144 | * @param ?string $image |
145 | * @return Adapter\Imagick |
146 | */ |
147 | public static function createImagick(int $width, int $height, ?string $image = null): Adapter\Imagick |
148 | { |
149 | return Imagick::create($width, $height, $image); |
150 | } |
151 | |
152 | /** |
153 | * Create a new indexed image resource and load it into a Imagick object |
154 | * |
155 | * @param int $width |
156 | * @param int $height |
157 | * @param ?string $image |
158 | * @return Adapter\Imagick |
159 | */ |
160 | public static function createImagickIndex(int $width, int $height, ?string $image = null): Adapter\Imagick |
161 | { |
162 | return Imagick::createIndex($width, $height, $image); |
163 | } |
164 | |
165 | } |