Overview

Packages

  • Image
  • None

Classes

  • Horde_Image
  • Horde_Image_Base
  • Horde_Image_Effect
  • Horde_Image_Effect_Border
  • Horde_Image_Effect_Gd_DropShadow
  • Horde_Image_Effect_Gd_RoundCorners
  • Horde_Image_Effect_Gd_TextWatermark
  • Horde_Image_Effect_Gd_Unsharpmask
  • Horde_Image_Effect_Im_Border
  • Horde_Image_Effect_Im_CenterCrop
  • Horde_Image_Effect_Im_Composite
  • Horde_Image_Effect_Im_DropShadow
  • Horde_Image_Effect_Im_LiquidResize
  • Horde_Image_Effect_Im_PhotoStack
  • Horde_Image_Effect_Im_PolaroidImage
  • Horde_Image_Effect_Im_RoundCorners
  • Horde_Image_Effect_Im_TextWatermark
  • Horde_Image_Effect_Im_Unsharpmask
  • Horde_Image_Effect_Imagick_Border
  • Horde_Image_Effect_Imagick_CenterCrop
  • Horde_Image_Effect_Imagick_Composite
  • Horde_Image_Effect_Imagick_DropShadow
  • Horde_Image_Effect_Imagick_LiquidResize
  • Horde_Image_Effect_Imagick_PhotoStack
  • Horde_Image_Effect_Imagick_PolaroidImage
  • Horde_Image_Effect_Imagick_RoundCorners
  • Horde_Image_Effect_Imagick_SmartCrop
  • Horde_Image_Effect_Imagick_TextWatermark
  • Horde_Image_Effect_Imagick_Unsharpmask
  • Horde_Image_Exception
  • Horde_Image_Exif
  • Horde_Image_Exif_Base
  • Horde_Image_Exif_Bundled
  • Horde_Image_Exif_Exiftool
  • Horde_Image_Exif_Parser_Base
  • Horde_Image_Exif_Php
  • Horde_Image_Gd
  • Horde_Image_Im
  • Horde_Image_Imagick
  • Horde_Image_Png
  • Horde_Image_Svg
  • Horde_Image_Swf
  • Horde_Image_Translation
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Image effect for adding a drop shadow.
  4:  *
  5:  * This algorithm is from the phpThumb project available at
  6:  * http://phpthumb.sourceforge.net and all credit for this script should go to
  7:  * James Heinrich <info@silisoftware.com>.  Modifications made to the code
  8:  * to fit it within the Horde framework and to adjust for our coding standards.
  9:  *
 10:  * @author Michael J. Rubinsky <mrubinsk@horde.org>
 11:  * @package Image
 12:  */
 13: class Horde_Image_Effect_Gd_DropShadow extends Horde_Image_Effect
 14: {
 15:     /**
 16:      * Valid parameters:
 17:      *
 18:      * @TODO
 19:      *
 20:      * @var array
 21:      */
 22:     protected $_params = array('distance' => 5,
 23:                                'width' => 2,
 24:                                'hexcolor' => '000000',
 25:                                'angle' => 215,
 26:                                'fade' => 10);
 27: 
 28:     /**
 29:      * Apply the drop_shadow effect.
 30:      *
 31:      * @return boolean
 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:         /* Creates the shadow */
 65:         $r = hexdec(substr($hexcolor, 0, 2));
 66:         $g = hexdec(substr($hexcolor, 2, 2));
 67:         $b = hexdec(substr($hexcolor, 4, 2));
 68: 
 69:         /* Essentially masks the original image and creates the shadow */
 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:         /* Overlays the original image */
 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:         // Merge the shadow and the original into the original.
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: }
API documentation generated by ApiGen