Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Density | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
perform | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 |
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 2013-05-26 |
13 | */ |
14 | |
15 | declare(strict_types=1); |
16 | |
17 | namespace Karla\Action; |
18 | |
19 | use Karla\Query; |
20 | use Karla\Action; |
21 | |
22 | /** |
23 | * Class for handeling density action |
24 | * |
25 | * @category Utility |
26 | * @author Johannes Skov Frandsen <jsf@greenoak.dk> |
27 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
28 | * @link https://github.com/localgod/karla Karla |
29 | */ |
30 | class Density implements Action |
31 | { |
32 | /** |
33 | * Width |
34 | * |
35 | * @var integer |
36 | */ |
37 | private int $width; |
38 | |
39 | /** |
40 | * Height |
41 | * |
42 | * @var integer |
43 | */ |
44 | private int $height; |
45 | |
46 | /** |
47 | * Is it an output argument |
48 | * |
49 | * @var boolean |
50 | */ |
51 | private bool $output; |
52 | |
53 | /** |
54 | * Set the density of the output image. |
55 | * |
56 | * @param integer $width |
57 | * The width of the image |
58 | * @param integer $height |
59 | * The height of the image |
60 | * @param boolean $output |
61 | * If output is true density is set for the resulting image |
62 | * If output is false density is used for reading the input image |
63 | * |
64 | * @throws \InvalidArgumentException |
65 | */ |
66 | public function __construct(int $width, int $height, bool $output) |
67 | { |
68 | $this->width = $width; |
69 | $this->height = $height; |
70 | $this->output = $output; |
71 | } |
72 | |
73 | /** |
74 | * (non-PHPdoc) |
75 | * |
76 | * @param Query $query |
77 | * The query to add the action to |
78 | * @return Query |
79 | * @see Action::perform() |
80 | * @throws \BadMethodCallException if density has already been called |
81 | */ |
82 | public function perform(Query $query): Query |
83 | { |
84 | $query->notWith('density', Query::ARGUMENT_TYPE_INPUT); |
85 | $query->notWith('density', Query::ARGUMENT_TYPE_OUTPUT); |
86 | |
87 | if ($this->output) { |
88 | $query->setOutputOption(" -density " . $this->width . "x" . $this->height); |
89 | } else { |
90 | $query->setInputOption(" -density " . $this->width . "x" . $this->height); |
91 | } |
92 | return $query; |
93 | } |
94 | } |