Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Crop | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| perform | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| 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 crop 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 Crop implements Action |
| 31 | { |
| 32 | /** |
| 33 | * Width |
| 34 | * @var integer |
| 35 | */ |
| 36 | private int|null $width; |
| 37 | |
| 38 | /** |
| 39 | * Height |
| 40 | * @var integer |
| 41 | */ |
| 42 | private int|null $height; |
| 43 | |
| 44 | /** |
| 45 | * X offset |
| 46 | * @var integer |
| 47 | */ |
| 48 | private int $xOffset; |
| 49 | |
| 50 | /** |
| 51 | * Y offset |
| 52 | * @var integer |
| 53 | */ |
| 54 | private int $yOffset; |
| 55 | |
| 56 | /** |
| 57 | * Construct a new crop action |
| 58 | * |
| 59 | * @param integer $width |
| 60 | * Image width |
| 61 | * @param integer $height |
| 62 | * Image height |
| 63 | * @param integer $xOffset |
| 64 | * X offset from upper-left corner |
| 65 | * @param integer $yOffset |
| 66 | * Y offset from upper-left corner |
| 67 | * |
| 68 | * @throws \InvalidArgumentException |
| 69 | */ |
| 70 | public function __construct(int|null $width, int|null $height, int $xOffset, int $yOffset) |
| 71 | { |
| 72 | $this->width = $width; |
| 73 | $this->height = $height; |
| 74 | $this->xOffset = $xOffset; |
| 75 | $this->yOffset = $yOffset; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * (non-PHPdoc) |
| 80 | * |
| 81 | * @param Query $query |
| 82 | * The query to add the action to |
| 83 | * @return Query |
| 84 | * @see Action::perform() |
| 85 | */ |
| 86 | public function perform(Query $query): Query |
| 87 | { |
| 88 | $query->notWith('crop', Query::ARGUMENT_TYPE_INPUT); |
| 89 | |
| 90 | $option = " -crop " . $this->width . "x" . $this->height; |
| 91 | |
| 92 | if ($this->xOffset >= 0) { |
| 93 | $option = $option . "+" . $this->xOffset; |
| 94 | } else { |
| 95 | $option = $option . $this->xOffset; |
| 96 | } |
| 97 | |
| 98 | if ($this->yOffset >= 0) { |
| 99 | $option = $option . "+" . $this->yOffset; |
| 100 | } else { |
| 101 | $option = $option . $this->yOffset; |
| 102 | } |
| 103 | |
| 104 | // http://www.imagemagick.org/Usage/crop/#crop_repage |
| 105 | $option = $option . " +repage "; |
| 106 | $query->setInputOption($option); |
| 107 | |
| 108 | return $query; |
| 109 | } |
| 110 | } |