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 round image corners.
  4:  *
  5:  * This algorithm is from the phpThumb project available at
  6:  * http://phpthumb.sourceforge.net and all credit (and complaints ;) for this
  7:  * script should go to James Heinrich <info@silisoftware.com>.  Modifications
  8:  * made to the code to fit it within the Horde framework and to adjust for our
  9:  * coding standards.
 10:  *
 11:  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
 12:  * @package Image
 13:  */
 14: class Horde_Image_Effect_Gd_RoundCorners extends Horde_Image_Effect
 15: {
 16:     /**
 17:      * Valid parameters:
 18:      *
 19:      * radius - Radius of rounded corners.
 20:      *
 21:      * @var array
 22:      */
 23:     protected $_params = array('radius' => 10);
 24: 
 25:     /**
 26:      * Apply the round_corners effect.
 27:      *
 28:      * @return boolean
 29:      */
 30:     public function apply()
 31:     {
 32:         // Original comments from phpThumb projet:
 33:         // generate mask at twice desired resolution and downsample afterwards
 34:         // for easy antialiasing mask is generated as a white double-size
 35:         // elipse on a triple-size black background and copy-paste-resampled
 36:         // onto a correct-size mask image as 4 corners due to errors when the
 37:         // entire mask is resampled at once (gray edges)
 38:         $radius_x = $radius_y = $this->_params['radius'];
 39:         $gdimg = $this->_image->_im;
 40:         $imgX = round($this->_image->call('imageSX', array($gdimg)));
 41:         $imgY = round($this->_image->call('imageSY', array($gdimg)));
 42:         $gdimg_cornermask_triple = $this->_image->create(round($radius_x * 6), round($radius_y * 6));
 43:         $gdimg_cornermask = $this->_image->create($imgX, $imgY);
 44:         $color_transparent = $this->_image->call('imageColorAllocate',
 45:                                                   array($gdimg_cornermask_triple,
 46:                                                         255,
 47:                                                         255,
 48:                                                         255));
 49: 
 50:         $this->_image->call('imageFilledEllipse',
 51:                              array($gdimg_cornermask_triple,
 52:                                    $radius_x * 3,
 53:                                    $radius_y * 3,
 54:                                    $radius_x * 4,
 55:                                    $radius_y * 4,
 56:                                    $color_transparent));
 57: 
 58:         $this->_image->call('imageFilledRectangle',
 59:                              array($gdimg_cornermask,
 60:                                    0,
 61:                                    0,
 62:                                    $imgX,
 63:                                    $imgY,
 64:                                    $color_transparent));
 65: 
 66:         $this->_image->call('imageCopyResampled',
 67:                              array($gdimg_cornermask,
 68:                                    $gdimg_cornermask_triple,
 69:                                    0,
 70:                                    0,
 71:                                    $radius_x,
 72:                                    $radius_y,
 73:                                    $radius_x,
 74:                                    $radius_y,
 75:                                    $radius_x * 2,
 76:                                    $radius_y * 2));
 77: 
 78:         $this->_image->call('imageCopyResampled',
 79:                              array($gdimg_cornermask,
 80:                                    $gdimg_cornermask_triple,
 81:                                    0,
 82:                                    $imgY - $radius_y,
 83:                                    $radius_x,
 84:                                    $radius_y * 3,
 85:                                    $radius_x,
 86:                                    $radius_y,
 87:                                    $radius_x * 2,
 88:                                    $radius_y * 2));
 89: 
 90:         $this->_image->call('imageCopyResampled',
 91:                              array($gdimg_cornermask,
 92:                                    $gdimg_cornermask_triple,
 93:                                    $imgX - $radius_x,
 94:                                    $imgY - $radius_y,
 95:                                    $radius_x * 3,
 96:                                    $radius_y * 3,
 97:                                    $radius_x,
 98:                                    $radius_y,
 99:                                    $radius_x * 2,
100:                                    $radius_y * 2));
101: 
102:         $this->_image->call('imageCopyResampled',
103:                              array($gdimg_cornermask,
104:                                    $gdimg_cornermask_triple,
105:                                    $imgX - $radius_x,
106:                                    0,
107:                                    $radius_x * 3,
108:                                    $radius_y,
109:                                    $radius_x,
110:                                    $radius_y,
111:                                    $radius_x * 2,
112:                                    $radius_y * 2));
113: 
114:         $result = $this->_image->_applyMask($gdimg_cornermask);
115:         $this->_image->call('imageDestroy', array($gdimg_cornermask));
116:         $this->_image->call('imageDestroy', array($gdimg_cornermask_triple));
117:         
118:         return true;
119:     }
120: 
121: }
API documentation generated by ApiGen