1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: |
|
23: |
|
24: | namespace WideImage\Operation;
|
25: |
|
26: | use WideImage\Exception\GDFunctionResultException;
|
27: |
|
28: | |
29: | |
30: | |
31: | |
32: |
|
33: | class AsNegative
|
34: | {
|
35: | |
36: | |
37: | |
38: | |
39: | |
40: |
|
41: | public function execute($image)
|
42: | {
|
43: | $palette = !$image->isTrueColor();
|
44: | $transparent = $image->isTransparent();
|
45: |
|
46: | if ($palette && $transparent) {
|
47: | $tcrgb = $image->getTransparentColorRGB();
|
48: | }
|
49: |
|
50: | $new = $image->asTrueColor();
|
51: |
|
52: | if (!imagefilter($new->getHandle(), IMG_FILTER_NEGATE)) {
|
53: | throw new GDFunctionResultException("imagefilter() returned false");
|
54: | }
|
55: |
|
56: | if ($palette) {
|
57: | $new = $new->asPalette();
|
58: |
|
59: | if ($transparent) {
|
60: | $irgb = array('red' => 255 - $tcrgb['red'], 'green' => 255 - $tcrgb['green'], 'blue' => 255 - $tcrgb['blue'], 'alpha' => 127);
|
61: |
|
62: |
|
63: | $new_tci = imagecolorexactalpha($new->getHandle(), $irgb['red'], $irgb['green'], $irgb['blue'], 127);
|
64: | $new->setTransparentColor($new_tci);
|
65: | }
|
66: | }
|
67: |
|
68: | return $new;
|
69: | }
|
70: | }
|
71: | |