Source for file Border.php
Documentation is available at Border.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
* This is a driver file contains the Image_Tools_Border class.
* Copyright (c) 2005-2006 Firman Wandayandi <firman@php.net>
* Redistribution and use in source and binary forms, with or without
* modification, are permitted under the terms of the BSD License.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* @author Firman Wandayandi <firman@php.net>
* @copyright Copyright (c) 2005-2006 Firman Wandayandi <firman@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Border.php,v 1.5 2006/11/23 22:17:31 firman Exp $
* Load Image_Tools as the base class.
require_once 'Image/Tools.php';
* Load Image_Color for color handling.
require_once 'Image/Color.php';
// {{{ Class: Image_Tools_Border
* This class provide border creation on an image.
* @author Firman Wandayandi <firman@php.net>
* @copyright Copyright (c) 2005-2006 Firman Wandayandi <firman@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php
* @version Release: 0.4.1
* image mixed Destination image, a filename or an image string
* data or a GD image resource.
'image' => null // An image.
* Available options for Image_Tools_Border.
* Available methods for Image_Tool_Border (only public methods).
* Image_Tools_Border API version.
* Initialize some internal variables.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
if (PEAR ::isError ($res)) {
* Make an image be a rounded edge.
* @param int $radius optional Radius size.
* @param mixed $background Background color.
* @param int $antiAlias Anti-alias factor.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
function rounded($radius = 3 , $background = 'FFFFFF', $antiAlias = 3 )
if (PEAR ::isError ($res)) {
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_resultImage');
$background = Image_Color ::hex2rgb ($background);
$antiAlias = min(3 , $antiAlias);
for ($i = 0 - $radius; $i <= $radius; $i++ ) {
$y = $i < 0 ? $i + $radius - 1 : $this->_iHeight - ($radius - $i);
for ($j = 0 - $radius; $j <= $radius; $j++ ) {
$x = $j < 0 ? $j + $radius - 1 : $this->_iWidth - ($radius - $j);
if ($i != 0 || $j != 0 ) {
$distance = round(sqrt(($i * $i) + ($j * $j)));
$opacity = $distance < $radius - $antiAlias ?
0 : max(0 , 100 - (($radius - $distance) * 33 ));
$opacity = $distance > $radius ? 100 : $opacity;
* Make an image bevel border.
* @param int $size Border size.
* @param mixed $highlight Highlight color.
* @param mixed $shadow Shadow color.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
function bevel($size = 8 , $highlight = 'FFFFFF', $shadow = '000000')
if (PEAR ::isError ($res)) {
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_resultImage');
$highlight = Image_Color ::hex2rgb ($highlight);
$shadow = Image_Color ::hex2rgb ($shadow);
// Create an image resource for highlight.
$iLight = imagecreate($this->_iWidth, $this->_iHeight);
// Create an image resource for shadow.
for ($j = 0; $j < $size; $j++ ) {
$opacity = 100 - (($j + 1 ) * (100 / $size));
0 , 0 , 1 , $this->_iHeight - (2 * $j), $opacity);
0 , 0 , $this->_iWidth - (2 * $j), 1 , $opacity);
0 , 0 , 1 , $this->_iHeight - (2 * $j), max(0 , $opacity - 10 ));
0 , 0 , $this->_iWidth - (2 * $j), 1 , max(0 , $opacity - 10 ));
// Free highlight and shadow image resources.
* This method is useless, use directly call for specific border style
* @return bool always TRUE.
* c-hanging-comment-ender-p: nil
Documentation generated on Thu, 23 Nov 2006 18:00:05 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|