Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Gd
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
6 / 6
13
100.00% covered (success)
100.00%
1 / 1
 blur
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 sharpen
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 negate
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 colorize
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 pixelate
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 pencil
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
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 */
14namespace Pop\Image\Filter;
15
16use Pop\Color\Color;
17
18/**
19 * Filter class for Gd
20 *
21 * @category   Pop
22 * @package    Pop\Image
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    4.0.0
27 */
28class Gd extends AbstractFilter
29{
30
31    /**
32     * Blur the image
33     *
34     * @param  int $amount
35     * @param  int $type
36     * @return Gd
37     */
38    public function blur(int $amount, int $type = IMG_FILTER_GAUSSIAN_BLUR): Gd
39    {
40        if ($this->hasImage()) {
41            for ($i = 1; $i <= $amount; $i++) {
42                imagefilter($this->image->getResource(), $type);
43            }
44        }
45
46        return $this;
47    }
48
49    /**
50     * Sharpen the image.
51     *
52     * @param  int $amount
53     * @return Gd
54     */
55    public function sharpen(int $amount): Gd
56    {
57        if ($this->hasImage()) {
58            imagefilter($this->image->getResource(), IMG_FILTER_SMOOTH, (0 - $amount));
59        }
60        return $this;
61    }
62
63    /**
64     * Create a negative of the image
65     *
66     * @return Gd
67     */
68    public function negate(): Gd
69    {
70        if ($this->hasImage()) {
71            imagefilter($this->image->getResource(), IMG_FILTER_NEGATE);
72        }
73        return $this;
74    }
75
76    /**
77     * Colorize the image
78     *
79     * @param  Color\Rgb $color
80     * @return Gd
81     */
82    public function colorize(Color\Rgb $color): Gd
83    {
84        if ($this->hasImage()) {
85            imagefilter($this->image->getResource(), IMG_FILTER_COLORIZE, $color->getR(), $color->getG(), $color->getB());
86        }
87        return $this;
88    }
89
90    /**
91     * Pixelate the image
92     *
93     * @param  int $px
94     * @return Gd
95     */
96    public function pixelate(int $px): Gd
97    {
98        if ($this->hasImage()) {
99            imagefilter($this->image->getResource(), IMG_FILTER_PIXELATE, $px, true);
100        }
101        return $this;
102    }
103
104    /**
105     * Apply a pencil/sketch effect to the image
106     *
107     * @return Gd
108     */
109    public function pencil(): Gd
110    {
111        if ($this->hasImage()) {
112            imagefilter($this->image->getResource(), IMG_FILTER_MEAN_REMOVAL);
113        }
114        return $this;
115    }
116
117}