1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Horde_Image_Effect_Gd_DropShadow extends Horde_Image_Effect
14: {
15: 16: 17: 18: 19: 20: 21:
22: protected $_params = array('distance' => 5,
23: 'width' => 2,
24: 'hexcolor' => '000000',
25: 'angle' => 215,
26: 'fade' => 10);
27:
28: 29: 30: 31: 32:
33: public function apply()
34: {
35: $distance = $this->_params['distance'];
36: $width = $this->_params['width'];
37: $hexcolor = $this->_params['hexcolor'];
38: $angle = $this->_params['angle'];
39: $fade = $this->_params['fade'];
40:
41: $width_shadow = cos(deg2rad($angle)) * ($distance + $width);
42: $height_shadow = sin(deg2rad($angle)) * ($distance + $width);
43: $gdimg = $this->_image->_im;
44: $imgX = $this->_image->call('imageSX', array($gdimg));
45: $imgY = $this->_image->call('imageSY', array($gdimg));
46:
47: $offset['x'] = cos(deg2rad($angle)) * ($distance + $width - 1);
48: $offset['y'] = sin(deg2rad($angle)) * ($distance + $width - 1);
49:
50: $tempImageWidth = $imgX + abs($offset['x']);
51: $tempImageHeight = $imgY + abs($offset['y']);
52: $gdimg_dropshadow_temp = $this->_image->create($tempImageWidth, $tempImageHeight);
53: $this->_image->call('imageAlphaBlending', array($gdimg_dropshadow_temp, false));
54: $this->_image->call('imageSaveAlpha', array($gdimg_dropshadow_temp, true));
55: $transparent1 = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, 0, 0, 0, 127));
56: $this->_image->call('imageFill', array($gdimg_dropshadow_temp, 0, 0, $transparent1));
57: for ($x = 0; $x < $imgX; $x++) {
58: for ($y = 0; $y < $imgY; $y++) {
59: $colorat = $this->_image->call('imageColorAt', array($gdimg, $x, $y));
60: $PixelMap[$x][$y] = $this->_image->call('imageColorsForIndex', array($gdimg, $colorat));
61: }
62: }
63:
64:
65: $r = hexdec(substr($hexcolor, 0, 2));
66: $g = hexdec(substr($hexcolor, 2, 2));
67: $b = hexdec(substr($hexcolor, 4, 2));
68:
69:
70: for ($x = 0; $x < $tempImageWidth; $x++) {
71: for ($y = 0; $y < $tempImageHeight; $y++) {
72: if (!isset($PixelMap[$x][$y]['alpha']) ||
73: ($PixelMap[$x][$y]['alpha'] > 0)) {
74: if (isset($PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha']) && ($PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha'] < 127)) {
75: $thisColor = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, $r, $g, $b, $PixelMap[$x + $offset['x']][$y + $offset['y']]['alpha']));
76: $this->_image->call('imageSetPixel',
77: array($gdimg_dropshadow_temp, $x, $y, $thisColor));
78: }
79: }
80: }
81: }
82:
83: $this->_image->call('imageAlphaBlending',
84: array($gdimg_dropshadow_temp, true));
85:
86: for ($x = 0; $x < $imgX; $x++) {
87: for ($y = 0; $y < $imgY; $y++) {
88: if ($PixelMap[$x][$y]['alpha'] < 127) {
89: $thisColor = $this->_image->call('imageColorAllocateAlpha', array($gdimg_dropshadow_temp, $PixelMap[$x][$y]['red'], $PixelMap[$x][$y]['green'], $PixelMap[$x][$y]['blue'], $PixelMap[$x][$y]['alpha']));
90: $this->_image->call('imageSetPixel',
91: array($gdimg_dropshadow_temp, $x, $y, $thisColor));
92: }
93: }
94: }
95:
96: $this->_image->call('imageSaveAlpha',
97: array($gdimg, true));
98: $this->_image->call('imageAlphaBlending',
99: array($gdimg, false));
100:
101:
102: $this->_image->call('imageCopyResampled',
103: array($gdimg, $gdimg_dropshadow_temp, 0, 0, 0, 0, $imgX, $imgY, $this->_image->call('imageSX', array($gdimg_dropshadow_temp)), $this->_image->call('imageSY', array($gdimg_dropshadow_temp))));
104:
105: $this->_image->call('imageDestroy', array($gdimg_dropshadow_temp));
106:
107: return true;
108: }
109:
110: }