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