Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
25 / 25 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
Identify | |
100.00% |
25 / 25 |
|
100.00% |
5 / 5 |
14 | |
100.00% |
1 / 1 |
in | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
execute | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
6 | |||
verbose | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getCommand | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
raw | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Karla ImageMagick wrapper library |
5 | * |
6 | * PHP Version 8.0< |
7 | * |
8 | * @category Utility |
9 | * @author Johannes Skov Frandsen <jsf@greenoak.dk> |
10 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
11 | * @link https://github.com/localgod/karla Karla |
12 | * @since 2012-04-05 |
13 | */ |
14 | |
15 | declare(strict_types=1); |
16 | |
17 | namespace Karla\Program; |
18 | |
19 | /** |
20 | * Class for wrapping ImageMagicks identify tool |
21 | * |
22 | * @category Utility |
23 | * @author Johannes Skov Frandsen <jsf@greenoak.dk> |
24 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
25 | * @link https://github.com/localgod/karla Karla |
26 | */ |
27 | class Identify extends ImageMagick |
28 | { |
29 | /** |
30 | * Input file |
31 | * |
32 | * @var string |
33 | */ |
34 | protected $inputFile; |
35 | |
36 | /** |
37 | * Add input argument |
38 | * |
39 | * @param string $filePath |
40 | * Input file path |
41 | * |
42 | * @return Identify |
43 | * @throws \InvalidArgumentException |
44 | */ |
45 | public function in($filePath) |
46 | { |
47 | if (! file_exists($filePath)) { |
48 | $message = 'The input file path (' . $filePath . ') is invalid or the file could not be located.'; |
49 | throw new \InvalidArgumentException($message); |
50 | } |
51 | $file = new \SplFileObject($filePath); |
52 | if ($file->isReadable()) { |
53 | $this->inputFile = '"' . $file->getPathname() . '"'; |
54 | } |
55 | $this->getQuery()->dirty(); |
56 | |
57 | return $this; |
58 | } |
59 | |
60 | /** |
61 | * Execute the command |
62 | * |
63 | * @param boolean $reset |
64 | * Reset the query |
65 | * @param boolean $raw |
66 | * Get the raw output |
67 | * |
68 | * @see Imagemagick#execute() |
69 | * @return string|\Karla\MetaData |
70 | */ |
71 | public function execute($reset = true, $raw = true): string|object |
72 | { |
73 | $result = parent::execute(false); |
74 | |
75 | if (! $raw) { |
76 | if ($this->getQuery()->isOptionSet('verbose', $this->getQuery()->getInputOptions())) { |
77 | $reset ? $this->getQuery()->reset() : null; |
78 | return new \Karla\MetaData($result, true); |
79 | } |
80 | $reset ? $this->getQuery()->reset() : null; |
81 | return new \Karla\MetaData($result); |
82 | } |
83 | |
84 | $reset ? $this->getQuery()->reset() : null; |
85 | return trim($result); |
86 | } |
87 | |
88 | /** |
89 | * Add verbose argument |
90 | * |
91 | * @return Identify |
92 | */ |
93 | public function verbose(): self |
94 | { |
95 | $this->getQuery()->notWith('verbose', \Karla\Query::ARGUMENT_TYPE_INPUT); |
96 | $this->getQuery()->setInputOption("-verbose "); |
97 | |
98 | return $this; |
99 | } |
100 | |
101 | /** |
102 | * (non-PHPdoc) |
103 | * |
104 | * @see Imagemagick#getCommand() |
105 | * @return string |
106 | */ |
107 | public function getCommand(): string |
108 | { |
109 | ! is_array($this->getQuery()->getInputOptions()) ? $this->getQuery()->setInputOption("") : null; |
110 | $options = $this->getQuery()->prepareOptions($this->getQuery()->getInputOptions()); |
111 | |
112 | return $this->binPath . $this->bin . ' ' . ($options == '' ? '' : $options . ' ') . $this->inputFile; |
113 | } |
114 | |
115 | /** |
116 | * Raw arguments directly to ImageMagick |
117 | * |
118 | * @param string $arguments |
119 | * Arguments |
120 | * @param boolean $input |
121 | * Defaults to an input option, use false to use it as an output option |
122 | * |
123 | * @return Identify |
124 | * @see ImageMagick::raw() |
125 | */ |
126 | public function raw($arguments, $input = true): self |
127 | { |
128 | parent::raw($arguments, $input); |
129 | |
130 | return $this; |
131 | } |
132 | } |