Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Resample
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 perform
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
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    2013-05-26
13 */
14
15declare(strict_types=1);
16
17namespace Karla\Action;
18
19use Karla\Query;
20use Karla\Action;
21
22/**
23 * Class for handling resample 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 */
30class Resample implements Action
31{
32    /**
33     * New width
34     *
35     * @var int
36     */
37    private int $newWidth;
38
39    /**
40     * New height
41     *
42     * @var int
43     */
44    private int $newHeight;
45
46    /**
47     * Construct a new size action
48     *
49     * @param int $newWidth New width
50     * @param int|null $newHeight New height
51     *
52     * @throws \InvalidArgumentException
53     */
54    public function __construct(int $newWidth, int|null $newHeight)
55    {
56        $this->newWidth = $newWidth;
57        $newHeight == null ? $this->newHeight = 0 : $this->newHeight = $newHeight;
58    }
59
60    /**
61     * (non-PHPdoc)
62     *
63     * @param Query $query The query to add the action to
64     *
65     * @see Action::perform()
66     */
67    public function perform(Query $query): Query
68    {
69        $query->notWith('resample', Query::ARGUMENT_TYPE_INPUT);
70        $query->notWith('resize', Query::ARGUMENT_TYPE_INPUT);
71
72        $option = " -resample '" . $this->newWidth . "x" . $this->newHeight . "' ";
73        $query->setInputOption($option);
74
75        return $query;
76    }
77}