@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
2 | + /** |
|
3 | 3 | ##DOC-SIGNATURE## |
4 | 4 | |
5 | 5 | This file is part of WideImage. |
@@ -17,9 +17,8 @@ discard block |
||
17 | 17 | You should have received a copy of the GNU Lesser General Public License |
18 | 18 | along with WideImage; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | - |
|
21 | - * @package Internal/Operations |
|
22 | - **/ |
|
20 | + * @package Internal/Operations |
|
21 | + **/ |
|
23 | 22 | |
24 | 23 | namespace WideImage\Operation; |
25 | 24 | |
@@ -30,137 +29,137 @@ discard block |
||
30 | 29 | */ |
31 | 30 | class AutoCrop |
32 | 31 | { |
33 | - /** |
|
34 | - * Executes the auto-crop operation on the $img |
|
35 | - * |
|
36 | - * @param \WideImage\Image $img |
|
37 | - * @param int $rgb_threshold The difference in RGB from $base_color |
|
38 | - * @param int $pixel_cutoff The number of pixels on each border that must be over $rgb_threshold |
|
39 | - * @param int $base_color The color that will get cropped |
|
40 | - * @return \WideImage\Image resulting auto-cropped image |
|
41 | - */ |
|
42 | - public function execute($img, $margin, $rgb_threshold, $pixel_cutoff, $base_color) |
|
43 | - { |
|
44 | - $margin = intval($margin); |
|
45 | - |
|
46 | - $rgb_threshold = intval($rgb_threshold); |
|
47 | - |
|
48 | - if ($rgb_threshold < 0) { |
|
49 | - $rgb_threshold = 0; |
|
50 | - } |
|
51 | - |
|
52 | - $pixel_cutoff = intval($pixel_cutoff); |
|
53 | - if ($pixel_cutoff <= 1) { |
|
54 | - $pixel_cutoff = 1; |
|
55 | - } |
|
56 | - |
|
57 | - if ($base_color === null) { |
|
58 | - $rgb_base = $img->getRGBAt(0, 0); |
|
59 | - } else { |
|
60 | - if ($base_color < 0) { |
|
61 | - return $img->copy(); |
|
62 | - } |
|
32 | + /** |
|
33 | + * Executes the auto-crop operation on the $img |
|
34 | + * |
|
35 | + * @param \WideImage\Image $img |
|
36 | + * @param int $rgb_threshold The difference in RGB from $base_color |
|
37 | + * @param int $pixel_cutoff The number of pixels on each border that must be over $rgb_threshold |
|
38 | + * @param int $base_color The color that will get cropped |
|
39 | + * @return \WideImage\Image resulting auto-cropped image |
|
40 | + */ |
|
41 | + public function execute($img, $margin, $rgb_threshold, $pixel_cutoff, $base_color) |
|
42 | + { |
|
43 | + $margin = intval($margin); |
|
44 | + |
|
45 | + $rgb_threshold = intval($rgb_threshold); |
|
46 | + |
|
47 | + if ($rgb_threshold < 0) { |
|
48 | + $rgb_threshold = 0; |
|
49 | + } |
|
50 | + |
|
51 | + $pixel_cutoff = intval($pixel_cutoff); |
|
52 | + if ($pixel_cutoff <= 1) { |
|
53 | + $pixel_cutoff = 1; |
|
54 | + } |
|
55 | + |
|
56 | + if ($base_color === null) { |
|
57 | + $rgb_base = $img->getRGBAt(0, 0); |
|
58 | + } else { |
|
59 | + if ($base_color < 0) { |
|
60 | + return $img->copy(); |
|
61 | + } |
|
63 | 62 | |
64 | - $rgb_base = $img->getColorRGB($base_color); |
|
65 | - } |
|
63 | + $rgb_base = $img->getColorRGB($base_color); |
|
64 | + } |
|
66 | 65 | |
67 | - $cut_rect = array('left' => 0, 'top' => 0, 'right' => $img->getWidth() - 1, 'bottom' => $img->getHeight() - 1); |
|
66 | + $cut_rect = array('left' => 0, 'top' => 0, 'right' => $img->getWidth() - 1, 'bottom' => $img->getHeight() - 1); |
|
68 | 67 | |
69 | - for ($y = 0; $y <= $cut_rect['bottom']; $y++) { |
|
70 | - $count = 0; |
|
68 | + for ($y = 0; $y <= $cut_rect['bottom']; $y++) { |
|
69 | + $count = 0; |
|
71 | 70 | |
72 | - for ($x = 0; $x <= $cut_rect['right']; $x++) { |
|
73 | - $rgb = $img->getRGBAt($x, $y); |
|
74 | - $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); |
|
71 | + for ($x = 0; $x <= $cut_rect['right']; $x++) { |
|
72 | + $rgb = $img->getRGBAt($x, $y); |
|
73 | + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); |
|
75 | 74 | |
76 | - if ($diff > $rgb_threshold) { |
|
77 | - $count++; |
|
75 | + if ($diff > $rgb_threshold) { |
|
76 | + $count++; |
|
78 | 77 | |
79 | - if ($count >= $pixel_cutoff) { |
|
80 | - $cut_rect['top'] = $y; |
|
81 | - break 2; |
|
82 | - } |
|
83 | - } |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - for ($y = $img->getHeight() - 1; $y >= $cut_rect['top']; $y--) { |
|
88 | - $count = 0; |
|
78 | + if ($count >= $pixel_cutoff) { |
|
79 | + $cut_rect['top'] = $y; |
|
80 | + break 2; |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + for ($y = $img->getHeight() - 1; $y >= $cut_rect['top']; $y--) { |
|
87 | + $count = 0; |
|
89 | 88 | |
90 | - for ($x = 0; $x <= $cut_rect['right']; $x++) { |
|
91 | - $rgb = $img->getRGBAt($x, $y); |
|
92 | - $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); |
|
89 | + for ($x = 0; $x <= $cut_rect['right']; $x++) { |
|
90 | + $rgb = $img->getRGBAt($x, $y); |
|
91 | + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); |
|
93 | 92 | |
94 | - if ($diff > $rgb_threshold) { |
|
95 | - $count++; |
|
93 | + if ($diff > $rgb_threshold) { |
|
94 | + $count++; |
|
96 | 95 | |
97 | - if ($count >= $pixel_cutoff) { |
|
98 | - $cut_rect['bottom'] = $y; |
|
99 | - break 2; |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - for ($x = 0; $x <= $cut_rect['right']; $x++) { |
|
106 | - $count = 0; |
|
96 | + if ($count >= $pixel_cutoff) { |
|
97 | + $cut_rect['bottom'] = $y; |
|
98 | + break 2; |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + for ($x = 0; $x <= $cut_rect['right']; $x++) { |
|
105 | + $count = 0; |
|
107 | 106 | |
108 | - for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) { |
|
109 | - $rgb = $img->getRGBAt($x, $y); |
|
110 | - $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); |
|
107 | + for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) { |
|
108 | + $rgb = $img->getRGBAt($x, $y); |
|
109 | + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); |
|
111 | 110 | |
112 | - if ($diff > $rgb_threshold) { |
|
113 | - $count++; |
|
111 | + if ($diff > $rgb_threshold) { |
|
112 | + $count++; |
|
114 | 113 | |
115 | - if ($count >= $pixel_cutoff) { |
|
116 | - $cut_rect['left'] = $x; |
|
117 | - break 2; |
|
118 | - } |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - for ($x = $cut_rect['right']; $x >= $cut_rect['left']; $x--) { |
|
124 | - $count = 0; |
|
114 | + if ($count >= $pixel_cutoff) { |
|
115 | + $cut_rect['left'] = $x; |
|
116 | + break 2; |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + for ($x = $cut_rect['right']; $x >= $cut_rect['left']; $x--) { |
|
123 | + $count = 0; |
|
125 | 124 | |
126 | - for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) { |
|
127 | - $rgb = $img->getRGBAt($x, $y); |
|
128 | - $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); |
|
125 | + for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) { |
|
126 | + $rgb = $img->getRGBAt($x, $y); |
|
127 | + $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']); |
|
129 | 128 | |
130 | - if ($diff > $rgb_threshold) { |
|
131 | - $count++; |
|
129 | + if ($diff > $rgb_threshold) { |
|
130 | + $count++; |
|
132 | 131 | |
133 | - if ($count >= $pixel_cutoff) { |
|
134 | - $cut_rect['right'] = $x; |
|
135 | - break 2; |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - $cut_rect = array( |
|
142 | - 'left' => $cut_rect['left'] - $margin, |
|
143 | - 'top' => $cut_rect['top'] - $margin, |
|
144 | - 'right' => $cut_rect['right'] + $margin, |
|
145 | - 'bottom' => $cut_rect['bottom'] + $margin |
|
146 | - ); |
|
147 | - |
|
148 | - if ($cut_rect['left'] < 0) { |
|
149 | - $cut_rect['left'] = 0; |
|
150 | - } |
|
151 | - |
|
152 | - if ($cut_rect['top'] < 0) { |
|
153 | - $cut_rect['top'] = 0; |
|
154 | - } |
|
155 | - |
|
156 | - if ($cut_rect['right'] >= $img->getWidth()) { |
|
157 | - $cut_rect['right'] = $img->getWidth() - 1; |
|
158 | - } |
|
159 | - |
|
160 | - if ($cut_rect['bottom'] >= $img->getHeight()) { |
|
161 | - $cut_rect['bottom'] = $img->getHeight() - 1; |
|
162 | - } |
|
163 | - |
|
164 | - return $img->crop($cut_rect['left'], $cut_rect['top'], $cut_rect['right'] - $cut_rect['left'] + 1, $cut_rect['bottom'] - $cut_rect['top'] + 1); |
|
165 | - } |
|
132 | + if ($count >= $pixel_cutoff) { |
|
133 | + $cut_rect['right'] = $x; |
|
134 | + break 2; |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + $cut_rect = array( |
|
141 | + 'left' => $cut_rect['left'] - $margin, |
|
142 | + 'top' => $cut_rect['top'] - $margin, |
|
143 | + 'right' => $cut_rect['right'] + $margin, |
|
144 | + 'bottom' => $cut_rect['bottom'] + $margin |
|
145 | + ); |
|
146 | + |
|
147 | + if ($cut_rect['left'] < 0) { |
|
148 | + $cut_rect['left'] = 0; |
|
149 | + } |
|
150 | + |
|
151 | + if ($cut_rect['top'] < 0) { |
|
152 | + $cut_rect['top'] = 0; |
|
153 | + } |
|
154 | + |
|
155 | + if ($cut_rect['right'] >= $img->getWidth()) { |
|
156 | + $cut_rect['right'] = $img->getWidth() - 1; |
|
157 | + } |
|
158 | + |
|
159 | + if ($cut_rect['bottom'] >= $img->getHeight()) { |
|
160 | + $cut_rect['bottom'] = $img->getHeight() - 1; |
|
161 | + } |
|
162 | + |
|
163 | + return $img->crop($cut_rect['left'], $cut_rect['top'], $cut_rect['right'] - $cut_rect['left'] + 1, $cut_rect['bottom'] - $cut_rect['top'] + 1); |
|
164 | + } |
|
166 | 165 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
2 | + /** |
|
3 | 3 | ##DOC-SIGNATURE## |
4 | 4 | |
5 | 5 | This file is part of WideImage. |
@@ -17,9 +17,8 @@ discard block |
||
17 | 17 | You should have received a copy of the GNU Lesser General Public License |
18 | 18 | along with WideImage; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | - |
|
21 | - * @package Internal/Operations |
|
22 | - **/ |
|
20 | + * @package Internal/Operations |
|
21 | + **/ |
|
23 | 22 | |
24 | 23 | namespace WideImage\Operation; |
25 | 24 | |
@@ -34,121 +33,121 @@ discard block |
||
34 | 33 | */ |
35 | 34 | class Unsharp |
36 | 35 | { |
37 | - /** |
|
38 | - * Returns sharpened image |
|
39 | - * |
|
40 | - * @param \WideImage\Image $image |
|
41 | - * @param float $amount |
|
42 | - * @param int $radius |
|
43 | - * @param float $threshold |
|
44 | - * @return \WideImage\Image |
|
45 | - */ |
|
46 | - public function execute($image, $amount, $radius, $threshold) |
|
47 | - { |
|
48 | - // Attempt to calibrate the parameters to Photoshop: |
|
49 | - if ($amount > 500) { |
|
50 | - $amount = 500; |
|
51 | - } |
|
36 | + /** |
|
37 | + * Returns sharpened image |
|
38 | + * |
|
39 | + * @param \WideImage\Image $image |
|
40 | + * @param float $amount |
|
41 | + * @param int $radius |
|
42 | + * @param float $threshold |
|
43 | + * @return \WideImage\Image |
|
44 | + */ |
|
45 | + public function execute($image, $amount, $radius, $threshold) |
|
46 | + { |
|
47 | + // Attempt to calibrate the parameters to Photoshop: |
|
48 | + if ($amount > 500) { |
|
49 | + $amount = 500; |
|
50 | + } |
|
52 | 51 | |
53 | - $amount = $amount * 0.016; |
|
52 | + $amount = $amount * 0.016; |
|
54 | 53 | |
55 | - if ($radius > 50) { |
|
56 | - $radius = 50; |
|
57 | - } |
|
54 | + if ($radius > 50) { |
|
55 | + $radius = 50; |
|
56 | + } |
|
58 | 57 | |
59 | - $radius = $radius * 2; |
|
58 | + $radius = $radius * 2; |
|
60 | 59 | |
61 | - if ($threshold > 255) { |
|
62 | - $threshold = 255; |
|
63 | - } |
|
60 | + if ($threshold > 255) { |
|
61 | + $threshold = 255; |
|
62 | + } |
|
64 | 63 | |
65 | - $radius = abs(round($radius)); // Only integers make sense. |
|
64 | + $radius = abs(round($radius)); // Only integers make sense. |
|
66 | 65 | |
67 | - if ($radius == 0) { |
|
68 | - return $image; |
|
69 | - } |
|
66 | + if ($radius == 0) { |
|
67 | + return $image; |
|
68 | + } |
|
70 | 69 | |
71 | - // Gaussian blur matrix |
|
72 | - $matrix = array( |
|
73 | - array(1, 2, 1), |
|
74 | - array(2, 4, 2), |
|
75 | - array(1, 2, 1) |
|
76 | - ); |
|
70 | + // Gaussian blur matrix |
|
71 | + $matrix = array( |
|
72 | + array(1, 2, 1), |
|
73 | + array(2, 4, 2), |
|
74 | + array(1, 2, 1) |
|
75 | + ); |
|
77 | 76 | |
78 | - $blurred = $image->applyConvolution($matrix, 16, 0); |
|
77 | + $blurred = $image->applyConvolution($matrix, 16, 0); |
|
79 | 78 | |
80 | - if ($threshold > 0) { |
|
81 | - // Calculate the difference between the blurred pixels and the original |
|
82 | - // and set the pixels |
|
83 | - for ($x = 0; $x < $image->getWidth(); $x++) { |
|
84 | - for ($y = 0; $y < $image->getHeight(); $y++) { |
|
85 | - $rgbOrig = $image->getRGBAt($x, $y); |
|
86 | - $rOrig = $rgbOrig["red"]; |
|
87 | - $gOrig = $rgbOrig["green"]; |
|
88 | - $bOrig = $rgbOrig["blue"]; |
|
79 | + if ($threshold > 0) { |
|
80 | + // Calculate the difference between the blurred pixels and the original |
|
81 | + // and set the pixels |
|
82 | + for ($x = 0; $x < $image->getWidth(); $x++) { |
|
83 | + for ($y = 0; $y < $image->getHeight(); $y++) { |
|
84 | + $rgbOrig = $image->getRGBAt($x, $y); |
|
85 | + $rOrig = $rgbOrig["red"]; |
|
86 | + $gOrig = $rgbOrig["green"]; |
|
87 | + $bOrig = $rgbOrig["blue"]; |
|
89 | 88 | |
90 | - $rgbBlur = $blurred->getRGBAt($x, $y); |
|
91 | - $rBlur = $rgbBlur["red"]; |
|
92 | - $gBlur = $rgbBlur["green"]; |
|
93 | - $bBlur = $rgbBlur["blue"]; |
|
89 | + $rgbBlur = $blurred->getRGBAt($x, $y); |
|
90 | + $rBlur = $rgbBlur["red"]; |
|
91 | + $gBlur = $rgbBlur["green"]; |
|
92 | + $bBlur = $rgbBlur["blue"]; |
|
94 | 93 | |
95 | - // When the masked pixels differ less from the original |
|
96 | - // than the threshold specifies, they are set to their original value. |
|
97 | - $rNew = (abs($rOrig - $rBlur) >= $threshold) |
|
98 | - ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) |
|
99 | - : $rOrig; |
|
100 | - $gNew = (abs($gOrig - $gBlur) >= $threshold) |
|
101 | - ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) |
|
102 | - : $gOrig; |
|
103 | - $bNew = (abs($bOrig - $bBlur) >= $threshold) |
|
104 | - ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) |
|
105 | - : $bOrig; |
|
106 | - $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); |
|
94 | + // When the masked pixels differ less from the original |
|
95 | + // than the threshold specifies, they are set to their original value. |
|
96 | + $rNew = (abs($rOrig - $rBlur) >= $threshold) |
|
97 | + ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) |
|
98 | + : $rOrig; |
|
99 | + $gNew = (abs($gOrig - $gBlur) >= $threshold) |
|
100 | + ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) |
|
101 | + : $gOrig; |
|
102 | + $bNew = (abs($bOrig - $bBlur) >= $threshold) |
|
103 | + ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) |
|
104 | + : $bOrig; |
|
105 | + $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); |
|
107 | 106 | |
108 | - if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { |
|
109 | - $image->setRGBAt($x, $y, $rgbNew); |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - } else { |
|
114 | - $w = $image->getWidth(); |
|
115 | - $h = $image->getHeight(); |
|
107 | + if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { |
|
108 | + $image->setRGBAt($x, $y, $rgbNew); |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + } else { |
|
113 | + $w = $image->getWidth(); |
|
114 | + $h = $image->getHeight(); |
|
116 | 115 | |
117 | - for ($x = 0; $x < $w; $x++) { |
|
118 | - for ($y = 0; $y < $h; $y++) { |
|
119 | - $rgbOrig = $image->getRGBAt($x, $y); |
|
120 | - $rOrig = $rgbOrig["red"]; |
|
121 | - $gOrig = $rgbOrig["green"]; |
|
122 | - $bOrig = $rgbOrig["blue"]; |
|
116 | + for ($x = 0; $x < $w; $x++) { |
|
117 | + for ($y = 0; $y < $h; $y++) { |
|
118 | + $rgbOrig = $image->getRGBAt($x, $y); |
|
119 | + $rOrig = $rgbOrig["red"]; |
|
120 | + $gOrig = $rgbOrig["green"]; |
|
121 | + $bOrig = $rgbOrig["blue"]; |
|
123 | 122 | |
124 | - $rgbBlur = $blurred->getRGBAt($x, $y); |
|
125 | - $rBlur = $rgbBlur["red"]; |
|
126 | - $gBlur = $rgbBlur["green"]; |
|
127 | - $bBlur = $rgbBlur["blue"]; |
|
123 | + $rgbBlur = $blurred->getRGBAt($x, $y); |
|
124 | + $rBlur = $rgbBlur["red"]; |
|
125 | + $gBlur = $rgbBlur["green"]; |
|
126 | + $bBlur = $rgbBlur["blue"]; |
|
128 | 127 | |
129 | - $rNew = static::bit(($amount * ($rOrig - $rBlur)) + $rOrig); |
|
130 | - $gNew = static::bit(($amount * ($gOrig - $gBlur)) + $gOrig); |
|
131 | - $bNew = static::bit(($amount * ($bOrig - $bBlur)) + $bOrig); |
|
132 | - $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); |
|
128 | + $rNew = static::bit(($amount * ($rOrig - $rBlur)) + $rOrig); |
|
129 | + $gNew = static::bit(($amount * ($gOrig - $gBlur)) + $gOrig); |
|
130 | + $bNew = static::bit(($amount * ($bOrig - $bBlur)) + $bOrig); |
|
131 | + $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0); |
|
133 | 132 | |
134 | - $image->setRGBAt($x, $y, $rgbNew); |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
133 | + $image->setRGBAt($x, $y, $rgbNew); |
|
134 | + } |
|
135 | + } |
|
136 | + } |
|
138 | 137 | |
139 | - return $image; |
|
140 | - } |
|
138 | + return $image; |
|
139 | + } |
|
141 | 140 | |
142 | - protected static function bit($val) |
|
143 | - { |
|
144 | - if ($val > 255) { |
|
145 | - return 255; |
|
146 | - } |
|
141 | + protected static function bit($val) |
|
142 | + { |
|
143 | + if ($val > 255) { |
|
144 | + return 255; |
|
145 | + } |
|
147 | 146 | |
148 | - if ($val < 0) { |
|
149 | - return 0; |
|
150 | - } |
|
147 | + if ($val < 0) { |
|
148 | + return 0; |
|
149 | + } |
|
151 | 150 | |
152 | - return $val; |
|
153 | - } |
|
151 | + return $val; |
|
152 | + } |
|
154 | 153 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
2 | + /** |
|
3 | 3 | ##DOC-SIGNATURE## |
4 | 4 | |
5 | 5 | This file is part of WideImage. |
@@ -17,9 +17,8 @@ discard block |
||
17 | 17 | You should have received a copy of the GNU Lesser General Public License |
18 | 18 | along with WideImage; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | - |
|
21 | - * @package Internal/Operations |
|
22 | - **/ |
|
20 | + * @package Internal/Operations |
|
21 | + **/ |
|
23 | 22 | |
24 | 23 | namespace WideImage\Operation; |
25 | 24 | |
@@ -32,29 +31,29 @@ discard block |
||
32 | 31 | */ |
33 | 32 | class Mirror |
34 | 33 | { |
35 | - /** |
|
36 | - * Returns a mirrored image |
|
37 | - * |
|
38 | - * @param \WideImage\Image $image |
|
39 | - * @return \WideImage\Image |
|
40 | - */ |
|
41 | - public function execute($image) |
|
42 | - { |
|
43 | - $new = $image->copy(); |
|
34 | + /** |
|
35 | + * Returns a mirrored image |
|
36 | + * |
|
37 | + * @param \WideImage\Image $image |
|
38 | + * @return \WideImage\Image |
|
39 | + */ |
|
40 | + public function execute($image) |
|
41 | + { |
|
42 | + $new = $image->copy(); |
|
44 | 43 | |
45 | - $width = $image->getWidth(); |
|
46 | - $height = $image->getHeight(); |
|
44 | + $width = $image->getWidth(); |
|
45 | + $height = $image->getHeight(); |
|
47 | 46 | |
48 | - if ($new->isTransparent()) { |
|
49 | - imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor()); |
|
50 | - } |
|
47 | + if ($new->isTransparent()) { |
|
48 | + imagefilledrectangle($new->getHandle(), 0, 0, $width, $height, $new->getTransparentColor()); |
|
49 | + } |
|
51 | 50 | |
52 | - for ($x = 0; $x < $width; $x++) { |
|
53 | - if (!imagecopy($new->getHandle(), $image->getHandle(), $x, 0, $width - $x - 1, 0, 1, $height)) { |
|
54 | - throw new GDFunctionResultException("imagecopy() returned false"); |
|
55 | - } |
|
56 | - } |
|
51 | + for ($x = 0; $x < $width; $x++) { |
|
52 | + if (!imagecopy($new->getHandle(), $image->getHandle(), $x, 0, $width - $x - 1, 0, 1, $height)) { |
|
53 | + throw new GDFunctionResultException("imagecopy() returned false"); |
|
54 | + } |
|
55 | + } |
|
57 | 56 | |
58 | - return $new; |
|
59 | - } |
|
57 | + return $new; |
|
58 | + } |
|
60 | 59 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
2 | + /** |
|
3 | 3 | ##DOC-SIGNATURE## |
4 | 4 | |
5 | 5 | This file is part of WideImage. |
@@ -17,9 +17,8 @@ discard block |
||
17 | 17 | You should have received a copy of the GNU Lesser General Public License |
18 | 18 | along with WideImage; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | - |
|
21 | - * @package Internal/Operations |
|
22 | - **/ |
|
20 | + * @package Internal/Operations |
|
21 | + **/ |
|
23 | 22 | |
24 | 23 | namespace WideImage\Operation; |
25 | 24 | |
@@ -35,62 +34,62 @@ discard block |
||
35 | 34 | */ |
36 | 35 | class Crop |
37 | 36 | { |
38 | - /** |
|
39 | - * Returns a cropped image |
|
40 | - * |
|
41 | - * @param \WideImage\Image $img |
|
42 | - * @param smart_coordinate $left |
|
43 | - * @param smart_coordinate $top |
|
44 | - * @param smart_coordinate $width |
|
45 | - * @param smart_coordinate $height |
|
46 | - * @return \WideImage\Image |
|
47 | - */ |
|
48 | - public function execute($img, $left, $top, $width, $height) |
|
49 | - { |
|
50 | - $width = Coordinate::fix($width, $img->getWidth(), $width); |
|
51 | - $height = Coordinate::fix($height, $img->getHeight(), $height); |
|
52 | - $left = Coordinate::fix($left, $img->getWidth(), $width); |
|
53 | - $top = Coordinate::fix($top, $img->getHeight(), $height); |
|
37 | + /** |
|
38 | + * Returns a cropped image |
|
39 | + * |
|
40 | + * @param \WideImage\Image $img |
|
41 | + * @param smart_coordinate $left |
|
42 | + * @param smart_coordinate $top |
|
43 | + * @param smart_coordinate $width |
|
44 | + * @param smart_coordinate $height |
|
45 | + * @return \WideImage\Image |
|
46 | + */ |
|
47 | + public function execute($img, $left, $top, $width, $height) |
|
48 | + { |
|
49 | + $width = Coordinate::fix($width, $img->getWidth(), $width); |
|
50 | + $height = Coordinate::fix($height, $img->getHeight(), $height); |
|
51 | + $left = Coordinate::fix($left, $img->getWidth(), $width); |
|
52 | + $top = Coordinate::fix($top, $img->getHeight(), $height); |
|
54 | 53 | |
55 | - if ($left < 0) { |
|
56 | - $width = $left + $width; |
|
57 | - $left = 0; |
|
58 | - } |
|
54 | + if ($left < 0) { |
|
55 | + $width = $left + $width; |
|
56 | + $left = 0; |
|
57 | + } |
|
59 | 58 | |
60 | - if ($width > $img->getWidth() - $left) { |
|
61 | - $width = $img->getWidth() - $left; |
|
62 | - } |
|
59 | + if ($width > $img->getWidth() - $left) { |
|
60 | + $width = $img->getWidth() - $left; |
|
61 | + } |
|
63 | 62 | |
64 | - if ($top < 0) { |
|
65 | - $height = $top + $height; |
|
66 | - $top = 0; |
|
67 | - } |
|
63 | + if ($top < 0) { |
|
64 | + $height = $top + $height; |
|
65 | + $top = 0; |
|
66 | + } |
|
68 | 67 | |
69 | - if ($height > $img->getHeight() - $top) { |
|
70 | - $height = $img->getHeight() - $top; |
|
71 | - } |
|
68 | + if ($height > $img->getHeight() - $top) { |
|
69 | + $height = $img->getHeight() - $top; |
|
70 | + } |
|
72 | 71 | |
73 | - if ($width <= 0 || $height <= 0) { |
|
74 | - throw new Exception("Can't crop outside of an image."); |
|
75 | - } |
|
72 | + if ($width <= 0 || $height <= 0) { |
|
73 | + throw new Exception("Can't crop outside of an image."); |
|
74 | + } |
|
76 | 75 | |
77 | - $new = $img->doCreate($width, $height); |
|
76 | + $new = $img->doCreate($width, $height); |
|
78 | 77 | |
79 | - if ($img->isTransparent() || $img instanceof PaletteImage) { |
|
80 | - $new->copyTransparencyFrom($img); |
|
78 | + if ($img->isTransparent() || $img instanceof PaletteImage) { |
|
79 | + $new->copyTransparencyFrom($img); |
|
81 | 80 | |
82 | - if (!imagecopyresized($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) { |
|
83 | - throw new GDFunctionResultException("imagecopyresized() returned false"); |
|
84 | - } |
|
85 | - } else { |
|
86 | - $new->alphaBlending(false); |
|
87 | - $new->saveAlpha(true); |
|
81 | + if (!imagecopyresized($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) { |
|
82 | + throw new GDFunctionResultException("imagecopyresized() returned false"); |
|
83 | + } |
|
84 | + } else { |
|
85 | + $new->alphaBlending(false); |
|
86 | + $new->saveAlpha(true); |
|
88 | 87 | |
89 | - if (!imagecopyresampled($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) { |
|
90 | - throw new GDFunctionResultException("imagecopyresampled() returned false"); |
|
91 | - } |
|
92 | - } |
|
88 | + if (!imagecopyresampled($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height)) { |
|
89 | + throw new GDFunctionResultException("imagecopyresampled() returned false"); |
|
90 | + } |
|
91 | + } |
|
93 | 92 | |
94 | - return $new; |
|
95 | - } |
|
93 | + return $new; |
|
94 | + } |
|
96 | 95 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
2 | + /** |
|
3 | 3 | ##DOC-SIGNATURE## |
4 | 4 | |
5 | 5 | This file is part of WideImage. |
@@ -17,9 +17,8 @@ discard block |
||
17 | 17 | You should have received a copy of the GNU Lesser General Public License |
18 | 18 | along with WideImage; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | - |
|
21 | - * @package Internal/Operations |
|
22 | - **/ |
|
20 | + * @package Internal/Operations |
|
21 | + **/ |
|
23 | 22 | |
24 | 23 | namespace WideImage\Operation; |
25 | 24 | |
@@ -32,39 +31,39 @@ discard block |
||
32 | 31 | */ |
33 | 32 | class AsNegative |
34 | 33 | { |
35 | - /** |
|
36 | - * Returns a greyscale copy of an image |
|
37 | - * |
|
38 | - * @param \WideImage\Image $image |
|
39 | - * @return \WideImage\Image |
|
40 | - */ |
|
41 | - public function execute($image) |
|
42 | - { |
|
43 | - $palette = !$image->isTrueColor(); |
|
44 | - $transparent = $image->isTransparent(); |
|
34 | + /** |
|
35 | + * Returns a greyscale copy of an image |
|
36 | + * |
|
37 | + * @param \WideImage\Image $image |
|
38 | + * @return \WideImage\Image |
|
39 | + */ |
|
40 | + public function execute($image) |
|
41 | + { |
|
42 | + $palette = !$image->isTrueColor(); |
|
43 | + $transparent = $image->isTransparent(); |
|
45 | 44 | |
46 | - if ($palette && $transparent) { |
|
47 | - $tcrgb = $image->getTransparentColorRGB(); |
|
48 | - } |
|
45 | + if ($palette && $transparent) { |
|
46 | + $tcrgb = $image->getTransparentColorRGB(); |
|
47 | + } |
|
49 | 48 | |
50 | - $new = $image->asTrueColor(); |
|
49 | + $new = $image->asTrueColor(); |
|
51 | 50 | |
52 | - if (!imagefilter($new->getHandle(), IMG_FILTER_NEGATE)) { |
|
53 | - throw new GDFunctionResultException("imagefilter() returned false"); |
|
54 | - } |
|
51 | + if (!imagefilter($new->getHandle(), IMG_FILTER_NEGATE)) { |
|
52 | + throw new GDFunctionResultException("imagefilter() returned false"); |
|
53 | + } |
|
55 | 54 | |
56 | - if ($palette) { |
|
57 | - $new = $new->asPalette(); |
|
55 | + if ($palette) { |
|
56 | + $new = $new->asPalette(); |
|
58 | 57 | |
59 | - if ($transparent) { |
|
60 | - $irgb = array('red' => 255 - $tcrgb['red'], 'green' => 255 - $tcrgb['green'], 'blue' => 255 - $tcrgb['blue'], 'alpha' => 127); |
|
58 | + if ($transparent) { |
|
59 | + $irgb = array('red' => 255 - $tcrgb['red'], 'green' => 255 - $tcrgb['green'], 'blue' => 255 - $tcrgb['blue'], 'alpha' => 127); |
|
61 | 60 | |
62 | - // needs imagecolorexactalpha instead of imagecolorexact, otherwise doesn't work on some transparent GIF images |
|
63 | - $new_tci = imagecolorexactalpha($new->getHandle(), $irgb['red'], $irgb['green'], $irgb['blue'], 127); |
|
64 | - $new->setTransparentColor($new_tci); |
|
65 | - } |
|
66 | - } |
|
61 | + // needs imagecolorexactalpha instead of imagecolorexact, otherwise doesn't work on some transparent GIF images |
|
62 | + $new_tci = imagecolorexactalpha($new->getHandle(), $irgb['red'], $irgb['green'], $irgb['blue'], 127); |
|
63 | + $new->setTransparentColor($new_tci); |
|
64 | + } |
|
65 | + } |
|
67 | 66 | |
68 | - return $new; |
|
69 | - } |
|
67 | + return $new; |
|
68 | + } |
|
70 | 69 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
2 | + /** |
|
3 | 3 | ##DOC-SIGNATURE## |
4 | 4 | |
5 | 5 | This file is part of WideImage. |
@@ -17,9 +17,8 @@ discard block |
||
17 | 17 | You should have received a copy of the GNU Lesser General Public License |
18 | 18 | along with WideImage; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | - |
|
21 | - * @package Internal/Operations |
|
22 | - **/ |
|
20 | + * @package Internal/Operations |
|
21 | + **/ |
|
23 | 22 | |
24 | 23 | namespace WideImage\Operation; |
25 | 24 | |
@@ -34,65 +33,65 @@ discard block |
||
34 | 33 | */ |
35 | 34 | class CopyChannelsPalette |
36 | 35 | { |
37 | - /** |
|
38 | - * Returns an image with only specified channels copied |
|
39 | - * |
|
40 | - * @param \WideImage\PaletteImage $img |
|
41 | - * @param array $channels |
|
42 | - * @return \WideImage\PaletteImage |
|
43 | - */ |
|
44 | - public function execute($img, $channels) |
|
45 | - { |
|
46 | - $blank = array('red' => 0, 'green' => 0, 'blue' => 0); |
|
36 | + /** |
|
37 | + * Returns an image with only specified channels copied |
|
38 | + * |
|
39 | + * @param \WideImage\PaletteImage $img |
|
40 | + * @param array $channels |
|
41 | + * @return \WideImage\PaletteImage |
|
42 | + */ |
|
43 | + public function execute($img, $channels) |
|
44 | + { |
|
45 | + $blank = array('red' => 0, 'green' => 0, 'blue' => 0); |
|
47 | 46 | |
48 | - if (isset($channels['alpha'])) { |
|
49 | - unset($channels['alpha']); |
|
50 | - } |
|
47 | + if (isset($channels['alpha'])) { |
|
48 | + unset($channels['alpha']); |
|
49 | + } |
|
51 | 50 | |
52 | - $width = $img->getWidth(); |
|
53 | - $height = $img->getHeight(); |
|
54 | - $copy = PaletteImage::create($width, $height); |
|
51 | + $width = $img->getWidth(); |
|
52 | + $height = $img->getHeight(); |
|
53 | + $copy = PaletteImage::create($width, $height); |
|
55 | 54 | |
56 | - if ($img->isTransparent()) { |
|
57 | - $otci = $img->getTransparentColor(); |
|
58 | - $TRGB = $img->getColorRGB($otci); |
|
59 | - $tci = $copy->allocateColor($TRGB); |
|
60 | - } else { |
|
61 | - $otci = null; |
|
62 | - $tci = null; |
|
63 | - } |
|
55 | + if ($img->isTransparent()) { |
|
56 | + $otci = $img->getTransparentColor(); |
|
57 | + $TRGB = $img->getColorRGB($otci); |
|
58 | + $tci = $copy->allocateColor($TRGB); |
|
59 | + } else { |
|
60 | + $otci = null; |
|
61 | + $tci = null; |
|
62 | + } |
|
64 | 63 | |
65 | - for ($x = 0; $x < $width; $x++) { |
|
66 | - for ($y = 0; $y < $height; $y++) { |
|
67 | - $ci = $img->getColorAt($x, $y); |
|
64 | + for ($x = 0; $x < $width; $x++) { |
|
65 | + for ($y = 0; $y < $height; $y++) { |
|
66 | + $ci = $img->getColorAt($x, $y); |
|
68 | 67 | |
69 | - if ($ci === $otci) { |
|
70 | - $copy->setColorAt($x, $y, $tci); |
|
71 | - continue; |
|
72 | - } |
|
68 | + if ($ci === $otci) { |
|
69 | + $copy->setColorAt($x, $y, $tci); |
|
70 | + continue; |
|
71 | + } |
|
73 | 72 | |
74 | - $RGB = $img->getColorRGB($ci); |
|
73 | + $RGB = $img->getColorRGB($ci); |
|
75 | 74 | |
76 | - $newRGB = $blank; |
|
75 | + $newRGB = $blank; |
|
77 | 76 | |
78 | - foreach ($channels as $channel) { |
|
79 | - $newRGB[$channel] = $RGB[$channel]; |
|
80 | - } |
|
77 | + foreach ($channels as $channel) { |
|
78 | + $newRGB[$channel] = $RGB[$channel]; |
|
79 | + } |
|
81 | 80 | |
82 | - $color = $copy->getExactColor($newRGB); |
|
81 | + $color = $copy->getExactColor($newRGB); |
|
83 | 82 | |
84 | - if ($color == -1) { |
|
85 | - $color = $copy->allocateColor($newRGB); |
|
86 | - } |
|
83 | + if ($color == -1) { |
|
84 | + $color = $copy->allocateColor($newRGB); |
|
85 | + } |
|
87 | 86 | |
88 | - $copy->setColorAt($x, $y, $color); |
|
89 | - } |
|
90 | - } |
|
87 | + $copy->setColorAt($x, $y, $color); |
|
88 | + } |
|
89 | + } |
|
91 | 90 | |
92 | - if ($img->isTransparent()) { |
|
93 | - $copy->setTransparentColor($tci); |
|
94 | - } |
|
91 | + if ($img->isTransparent()) { |
|
92 | + $copy->setTransparentColor($tci); |
|
93 | + } |
|
95 | 94 | |
96 | - return $copy; |
|
97 | - } |
|
95 | + return $copy; |
|
96 | + } |
|
98 | 97 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
2 | + /** |
|
3 | 3 | ##DOC-SIGNATURE## |
4 | 4 | |
5 | 5 | This file is part of WideImage. |
@@ -17,9 +17,8 @@ discard block |
||
17 | 17 | You should have received a copy of the GNU Lesser General Public License |
18 | 18 | along with WideImage; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | - |
|
21 | - * @package Internal/Operations |
|
22 | - **/ |
|
20 | + * @package Internal/Operations |
|
21 | + **/ |
|
23 | 22 | |
24 | 23 | namespace WideImage\Operation; |
25 | 24 | |
@@ -33,77 +32,77 @@ discard block |
||
33 | 32 | */ |
34 | 33 | class ResizeCanvas |
35 | 34 | { |
36 | - /** |
|
37 | - * Returns an image with a resized canvas |
|
38 | - * |
|
39 | - * The image is filled with $color. Use $scale to determine, when to resize. |
|
40 | - * |
|
41 | - * @param \WideImage\Image $img |
|
42 | - * @param smart_coordinate $width |
|
43 | - * @param smart_coordinate $height |
|
44 | - * @param smart_coordinate $left |
|
45 | - * @param smart_coordinate $top |
|
46 | - * @param int $color |
|
47 | - * @param string $scale 'up', 'down', 'any' |
|
48 | - * @param boolean $merge |
|
49 | - * @return \WideImage\Image |
|
50 | - */ |
|
51 | - public function execute($img, $width, $height, $left, $top, $color, $scale, $merge) |
|
52 | - { |
|
53 | - $new_width = Coordinate::fix($width, $img->getWidth()); |
|
54 | - $new_height = Coordinate::fix($height, $img->getHeight()); |
|
35 | + /** |
|
36 | + * Returns an image with a resized canvas |
|
37 | + * |
|
38 | + * The image is filled with $color. Use $scale to determine, when to resize. |
|
39 | + * |
|
40 | + * @param \WideImage\Image $img |
|
41 | + * @param smart_coordinate $width |
|
42 | + * @param smart_coordinate $height |
|
43 | + * @param smart_coordinate $left |
|
44 | + * @param smart_coordinate $top |
|
45 | + * @param int $color |
|
46 | + * @param string $scale 'up', 'down', 'any' |
|
47 | + * @param boolean $merge |
|
48 | + * @return \WideImage\Image |
|
49 | + */ |
|
50 | + public function execute($img, $width, $height, $left, $top, $color, $scale, $merge) |
|
51 | + { |
|
52 | + $new_width = Coordinate::fix($width, $img->getWidth()); |
|
53 | + $new_height = Coordinate::fix($height, $img->getHeight()); |
|
55 | 54 | |
56 | - if ($scale == 'down') { |
|
57 | - $new_width = min($new_width, $img->getWidth()); |
|
58 | - $new_height = min($new_height, $img->getHeight()); |
|
59 | - } elseif ($scale == 'up') { |
|
60 | - $new_width = max($new_width, $img->getWidth()); |
|
61 | - $new_height = max($new_height, $img->getHeight()); |
|
62 | - } |
|
55 | + if ($scale == 'down') { |
|
56 | + $new_width = min($new_width, $img->getWidth()); |
|
57 | + $new_height = min($new_height, $img->getHeight()); |
|
58 | + } elseif ($scale == 'up') { |
|
59 | + $new_width = max($new_width, $img->getWidth()); |
|
60 | + $new_height = max($new_height, $img->getHeight()); |
|
61 | + } |
|
63 | 62 | |
64 | - $new = WideImage::createTrueColorImage($new_width, $new_height); |
|
63 | + $new = WideImage::createTrueColorImage($new_width, $new_height); |
|
65 | 64 | |
66 | - if ($img->isTrueColor()) { |
|
67 | - if ($color === null) { |
|
68 | - $color = $new->allocateColorAlpha(0, 0, 0, 127); |
|
69 | - } |
|
70 | - } else { |
|
71 | - imagepalettecopy($new->getHandle(), $img->getHandle()); |
|
65 | + if ($img->isTrueColor()) { |
|
66 | + if ($color === null) { |
|
67 | + $color = $new->allocateColorAlpha(0, 0, 0, 127); |
|
68 | + } |
|
69 | + } else { |
|
70 | + imagepalettecopy($new->getHandle(), $img->getHandle()); |
|
72 | 71 | |
73 | - if ($img->isTransparent()) { |
|
74 | - $new->copyTransparencyFrom($img); |
|
75 | - $tc_rgb = $img->getTransparentColorRGB(); |
|
76 | - $t_color = $new->allocateColorAlpha($tc_rgb); |
|
77 | - } |
|
72 | + if ($img->isTransparent()) { |
|
73 | + $new->copyTransparencyFrom($img); |
|
74 | + $tc_rgb = $img->getTransparentColorRGB(); |
|
75 | + $t_color = $new->allocateColorAlpha($tc_rgb); |
|
76 | + } |
|
78 | 77 | |
79 | - if ($color === null) { |
|
80 | - if ($img->isTransparent()) { |
|
81 | - $color = $t_color; |
|
82 | - } else { |
|
83 | - $color = $new->allocateColorAlpha(255, 0, 127, 127); |
|
84 | - } |
|
78 | + if ($color === null) { |
|
79 | + if ($img->isTransparent()) { |
|
80 | + $color = $t_color; |
|
81 | + } else { |
|
82 | + $color = $new->allocateColorAlpha(255, 0, 127, 127); |
|
83 | + } |
|
85 | 84 | |
86 | - imagecolortransparent($new->getHandle(), $color); |
|
87 | - } |
|
88 | - } |
|
85 | + imagecolortransparent($new->getHandle(), $color); |
|
86 | + } |
|
87 | + } |
|
89 | 88 | |
90 | - $new->fill(0, 0, $color); |
|
89 | + $new->fill(0, 0, $color); |
|
91 | 90 | |
92 | - $x = Coordinate::fix($left, $new->getWidth(), $img->getWidth()); |
|
93 | - $y = Coordinate::fix($top, $new->getHeight(), $img->getHeight()); |
|
91 | + $x = Coordinate::fix($left, $new->getWidth(), $img->getWidth()); |
|
92 | + $y = Coordinate::fix($top, $new->getHeight(), $img->getHeight()); |
|
94 | 93 | |
95 | - // blending for truecolor images |
|
96 | - if ($img->isTrueColor()) { |
|
97 | - $new->alphaBlending($merge); |
|
98 | - } |
|
94 | + // blending for truecolor images |
|
95 | + if ($img->isTrueColor()) { |
|
96 | + $new->alphaBlending($merge); |
|
97 | + } |
|
99 | 98 | |
100 | - // not-blending for palette images |
|
101 | - if (!$merge && !$img->isTrueColor() && isset($t_color)) { |
|
102 | - $new->getCanvas()->filledRectangle($x, $y, $x + $img->getWidth(), $y + $img->getHeight(), $t_color); |
|
103 | - } |
|
99 | + // not-blending for palette images |
|
100 | + if (!$merge && !$img->isTrueColor() && isset($t_color)) { |
|
101 | + $new->getCanvas()->filledRectangle($x, $y, $x + $img->getWidth(), $y + $img->getHeight(), $t_color); |
|
102 | + } |
|
104 | 103 | |
105 | - $img->copyTo($new, $x, $y); |
|
104 | + $img->copyTo($new, $x, $y); |
|
106 | 105 | |
107 | - return $new; |
|
108 | - } |
|
106 | + return $new; |
|
107 | + } |
|
109 | 108 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
2 | + /** |
|
3 | 3 | ##DOC-SIGNATURE## |
4 | 4 | |
5 | 5 | This file is part of WideImage. |
@@ -17,9 +17,8 @@ discard block |
||
17 | 17 | You should have received a copy of the GNU Lesser General Public License |
18 | 18 | along with WideImage; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | - |
|
21 | - * @package Internal/Operations |
|
22 | - **/ |
|
20 | + * @package Internal/Operations |
|
21 | + **/ |
|
23 | 22 | |
24 | 23 | namespace WideImage\Operation; |
25 | 24 | |
@@ -32,21 +31,21 @@ discard block |
||
32 | 31 | */ |
33 | 32 | class CorrectGamma |
34 | 33 | { |
35 | - /** |
|
36 | - * Executes imagegammacorrect() |
|
37 | - * |
|
38 | - * @param \WideImage\Image $image |
|
39 | - * @param numeric $input_gamma |
|
40 | - * @param numeric $output_gamma |
|
41 | - * @return \WideImage\TrueColorImage |
|
42 | - */ |
|
43 | - public function execute($image, $input_gamma, $output_gamma) { |
|
44 | - $new = $image->copy(); |
|
34 | + /** |
|
35 | + * Executes imagegammacorrect() |
|
36 | + * |
|
37 | + * @param \WideImage\Image $image |
|
38 | + * @param numeric $input_gamma |
|
39 | + * @param numeric $output_gamma |
|
40 | + * @return \WideImage\TrueColorImage |
|
41 | + */ |
|
42 | + public function execute($image, $input_gamma, $output_gamma) { |
|
43 | + $new = $image->copy(); |
|
45 | 44 | |
46 | - if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma)) { |
|
47 | - throw new GDFunctionResultException("imagegammacorrect() returned false"); |
|
48 | - } |
|
45 | + if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma)) { |
|
46 | + throw new GDFunctionResultException("imagegammacorrect() returned false"); |
|
47 | + } |
|
49 | 48 | |
50 | - return $new; |
|
51 | - } |
|
49 | + return $new; |
|
50 | + } |
|
52 | 51 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * @author Tomasz Kapusta |
|
4 | - * @copyright 2010 |
|
2 | + /** |
|
3 | + * @author Tomasz Kapusta |
|
4 | + * @copyright 2010 |
|
5 | 5 | |
6 | 6 | This file is part of WideImage. |
7 | 7 | |
@@ -18,9 +18,8 @@ discard block |
||
18 | 18 | You should have received a copy of the GNU Lesser General Public License |
19 | 19 | along with WideImage; if not, write to the Free Software |
20 | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21 | - |
|
22 | - * @package Internal/Operations |
|
23 | - **/ |
|
21 | + * @package Internal/Operations |
|
22 | + **/ |
|
24 | 23 | |
25 | 24 | namespace WideImage\Operation; |
26 | 25 | |
@@ -31,137 +30,137 @@ discard block |
||
31 | 30 | */ |
32 | 31 | class AddNoise |
33 | 32 | { |
34 | - /** |
|
35 | - * Returns image with noise added |
|
36 | - * |
|
37 | - * @param \WideImage\Image $image |
|
38 | - * @param float $amount |
|
39 | - * @param const $type |
|
40 | - * @param float $threshold |
|
41 | - * @return \WideImage\Image |
|
42 | - */ |
|
43 | - public function execute($image, $amount, $type) { |
|
44 | - switch ($type) { |
|
45 | - case 'salt&pepper': |
|
46 | - $fun = 'saltPepperNoise_fun'; |
|
47 | - break; |
|
48 | - case 'color': |
|
49 | - $fun = 'colorNoise_fun'; |
|
50 | - break; |
|
51 | - default : |
|
52 | - $fun = 'monoNoise_fun'; |
|
53 | - break; |
|
54 | - } |
|
33 | + /** |
|
34 | + * Returns image with noise added |
|
35 | + * |
|
36 | + * @param \WideImage\Image $image |
|
37 | + * @param float $amount |
|
38 | + * @param const $type |
|
39 | + * @param float $threshold |
|
40 | + * @return \WideImage\Image |
|
41 | + */ |
|
42 | + public function execute($image, $amount, $type) { |
|
43 | + switch ($type) { |
|
44 | + case 'salt&pepper': |
|
45 | + $fun = 'saltPepperNoise_fun'; |
|
46 | + break; |
|
47 | + case 'color': |
|
48 | + $fun = 'colorNoise_fun'; |
|
49 | + break; |
|
50 | + default : |
|
51 | + $fun = 'monoNoise_fun'; |
|
52 | + break; |
|
53 | + } |
|
55 | 54 | |
56 | - return static::filter($image->asTrueColor(), $fun, $amount); |
|
57 | - } |
|
55 | + return static::filter($image->asTrueColor(), $fun, $amount); |
|
56 | + } |
|
58 | 57 | |
59 | - /** |
|
60 | - * Returns image with every pixel changed by specififed function |
|
61 | - * |
|
62 | - * @param \WideImage\Image $image |
|
63 | - * @param str $function |
|
64 | - * @param int $value |
|
65 | - * @return \WideImage\Image |
|
66 | - */ |
|
67 | - public function filter($image, $function, $value) |
|
68 | - { |
|
69 | - for ($y = 0; $y < $image->getHeight(); $y++) { |
|
70 | - for ($x = 0; $x< $image->getWidth(); $x++) { |
|
71 | - $rgb = imagecolorat($image->getHandle(), $x, $y); |
|
58 | + /** |
|
59 | + * Returns image with every pixel changed by specififed function |
|
60 | + * |
|
61 | + * @param \WideImage\Image $image |
|
62 | + * @param str $function |
|
63 | + * @param int $value |
|
64 | + * @return \WideImage\Image |
|
65 | + */ |
|
66 | + public function filter($image, $function, $value) |
|
67 | + { |
|
68 | + for ($y = 0; $y < $image->getHeight(); $y++) { |
|
69 | + for ($x = 0; $x< $image->getWidth(); $x++) { |
|
70 | + $rgb = imagecolorat($image->getHandle(), $x, $y); |
|
72 | 71 | |
73 | - $a = ($rgb >> 24) & 0xFF; |
|
74 | - $r = ($rgb >> 16) & 0xFF; |
|
75 | - $g = ($rgb >> 8) & 0xFF; |
|
76 | - $b = $rgb & 0xFF; |
|
72 | + $a = ($rgb >> 24) & 0xFF; |
|
73 | + $r = ($rgb >> 16) & 0xFF; |
|
74 | + $g = ($rgb >> 8) & 0xFF; |
|
75 | + $b = $rgb & 0xFF; |
|
77 | 76 | |
78 | - static::$function($r, $g, $b, $value); |
|
77 | + static::$function($r, $g, $b, $value); |
|
79 | 78 | |
80 | - $color = imagecolorallocatealpha($image->getHandle(), $r, $g, $b, $a); |
|
81 | - imagesetpixel($image->getHandle(), $x, $y, $color); |
|
82 | - } |
|
83 | - } |
|
79 | + $color = imagecolorallocatealpha($image->getHandle(), $r, $g, $b, $a); |
|
80 | + imagesetpixel($image->getHandle(), $x, $y, $color); |
|
81 | + } |
|
82 | + } |
|
84 | 83 | |
85 | - return $image; |
|
86 | - } |
|
84 | + return $image; |
|
85 | + } |
|
87 | 86 | |
88 | - /** |
|
89 | - * Adds color noise by altering given R,G,B values using specififed amount |
|
90 | - * |
|
91 | - * @param int $r |
|
92 | - * @param int $g |
|
93 | - * @param int $b |
|
94 | - * @param int $value |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public function colorNoise_fun(&$r, &$g, &$b, $amount) |
|
98 | - { |
|
99 | - $r = static::byte($r + mt_rand(0, $amount) - ($amount >> 1) ); |
|
100 | - $g = static::byte($g + mt_rand(0, $amount) - ($amount >> 1) ); |
|
101 | - $b = static::byte($b + mt_rand(0, $amount) - ($amount >> 1) ); |
|
102 | - } |
|
87 | + /** |
|
88 | + * Adds color noise by altering given R,G,B values using specififed amount |
|
89 | + * |
|
90 | + * @param int $r |
|
91 | + * @param int $g |
|
92 | + * @param int $b |
|
93 | + * @param int $value |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function colorNoise_fun(&$r, &$g, &$b, $amount) |
|
97 | + { |
|
98 | + $r = static::byte($r + mt_rand(0, $amount) - ($amount >> 1) ); |
|
99 | + $g = static::byte($g + mt_rand(0, $amount) - ($amount >> 1) ); |
|
100 | + $b = static::byte($b + mt_rand(0, $amount) - ($amount >> 1) ); |
|
101 | + } |
|
103 | 102 | |
104 | - /** |
|
105 | - * Adds mono noise by altering given R,G,B values using specififed amount |
|
106 | - * |
|
107 | - * @param int $r |
|
108 | - * @param int $g |
|
109 | - * @param int $b |
|
110 | - * @param int $value |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - public function monoNoise_fun(&$r, &$g, &$b, $amount) |
|
114 | - { |
|
115 | - $rand = mt_rand(0, $amount) - ($amount >> 1); |
|
103 | + /** |
|
104 | + * Adds mono noise by altering given R,G,B values using specififed amount |
|
105 | + * |
|
106 | + * @param int $r |
|
107 | + * @param int $g |
|
108 | + * @param int $b |
|
109 | + * @param int $value |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + public function monoNoise_fun(&$r, &$g, &$b, $amount) |
|
113 | + { |
|
114 | + $rand = mt_rand(0, $amount) - ($amount >> 1); |
|
116 | 115 | |
117 | - $r = static::byte($r + $rand); |
|
118 | - $g = static::byte($g + $rand); |
|
119 | - $b = static::byte($b + $rand); |
|
120 | - } |
|
116 | + $r = static::byte($r + $rand); |
|
117 | + $g = static::byte($g + $rand); |
|
118 | + $b = static::byte($b + $rand); |
|
119 | + } |
|
121 | 120 | |
122 | - /** |
|
123 | - * Adds salt&pepper noise by altering given R,G,B values using specififed amount |
|
124 | - * |
|
125 | - * @param int $r |
|
126 | - * @param int $g |
|
127 | - * @param int $b |
|
128 | - * @param int $value |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - public function saltPepperNoise_fun(&$r, &$g, &$b, $amount) |
|
132 | - { |
|
133 | - if (mt_rand(0, 255 - $amount) != 0) { |
|
134 | - return; |
|
135 | - } |
|
121 | + /** |
|
122 | + * Adds salt&pepper noise by altering given R,G,B values using specififed amount |
|
123 | + * |
|
124 | + * @param int $r |
|
125 | + * @param int $g |
|
126 | + * @param int $b |
|
127 | + * @param int $value |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + public function saltPepperNoise_fun(&$r, &$g, &$b, $amount) |
|
131 | + { |
|
132 | + if (mt_rand(0, 255 - $amount) != 0) { |
|
133 | + return; |
|
134 | + } |
|
136 | 135 | |
137 | - $rand = mt_rand(0, 1); |
|
136 | + $rand = mt_rand(0, 1); |
|
138 | 137 | |
139 | - switch ($rand) { |
|
140 | - case 0: |
|
141 | - $r = $g = $b = 0; |
|
142 | - break; |
|
143 | - case 1: |
|
144 | - $r = $g = $b = 255; |
|
145 | - break; |
|
146 | - } |
|
147 | - } |
|
138 | + switch ($rand) { |
|
139 | + case 0: |
|
140 | + $r = $g = $b = 0; |
|
141 | + break; |
|
142 | + case 1: |
|
143 | + $r = $g = $b = 255; |
|
144 | + break; |
|
145 | + } |
|
146 | + } |
|
148 | 147 | |
149 | - /** |
|
150 | - * Returns value within (0,255) |
|
151 | - * |
|
152 | - * @param int $b |
|
153 | - * @return int |
|
154 | - */ |
|
155 | - public function byte($b) |
|
156 | - { |
|
157 | - if ($b > 255) { |
|
158 | - return 255; |
|
159 | - } |
|
148 | + /** |
|
149 | + * Returns value within (0,255) |
|
150 | + * |
|
151 | + * @param int $b |
|
152 | + * @return int |
|
153 | + */ |
|
154 | + public function byte($b) |
|
155 | + { |
|
156 | + if ($b > 255) { |
|
157 | + return 255; |
|
158 | + } |
|
160 | 159 | |
161 | - if ($b < 0) { |
|
162 | - return 0; |
|
163 | - } |
|
160 | + if ($b < 0) { |
|
161 | + return 0; |
|
162 | + } |
|
164 | 163 | |
165 | - return (int) $b; |
|
166 | - } |
|
164 | + return (int) $b; |
|
165 | + } |
|
167 | 166 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function filter($image, $function, $value) |
68 | 68 | { |
69 | 69 | for ($y = 0; $y < $image->getHeight(); $y++) { |
70 | - for ($x = 0; $x< $image->getWidth(); $x++) { |
|
70 | + for ($x = 0; $x < $image->getWidth(); $x++) { |
|
71 | 71 | $rgb = imagecolorat($image->getHandle(), $x, $y); |
72 | 72 | |
73 | 73 | $a = ($rgb >> 24) & 0xFF; |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function colorNoise_fun(&$r, &$g, &$b, $amount) |
98 | 98 | { |
99 | - $r = static::byte($r + mt_rand(0, $amount) - ($amount >> 1) ); |
|
100 | - $g = static::byte($g + mt_rand(0, $amount) - ($amount >> 1) ); |
|
101 | - $b = static::byte($b + mt_rand(0, $amount) - ($amount >> 1) ); |
|
99 | + $r = static::byte($r + mt_rand(0, $amount) - ($amount >> 1)); |
|
100 | + $g = static::byte($g + mt_rand(0, $amount) - ($amount >> 1)); |
|
101 | + $b = static::byte($b + mt_rand(0, $amount) - ($amount >> 1)); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -162,6 +162,6 @@ discard block |
||
162 | 162 | return 0; |
163 | 163 | } |
164 | 164 | |
165 | - return (int) $b; |
|
165 | + return (int)$b; |
|
166 | 166 | } |
167 | 167 | } |