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-2008 Firman Wandayandi <firman@php.net>
* This source file is subject to the BSD License license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to pear-dev@list.php.net so we can send you a copy immediately.
* @author Firman Wandayandi <firman@php.net>
* @copyright Copyright (c) 2005-2008 Firman Wandayandi <firman@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Border.php,v 1.7 2008/05/26 06:13:06 firman Exp $
require_once 'Image/Tools.php';
require_once 'Image/Tools/Utils.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: 1.0.0RC1
* image mixed Destination image, a filename or an image string
* data or a GD image resource.
* style string Border style
* params array Parameters
* Available options for Image_Tools_Border.
* Available methods for Image_Tool_Border (only public methods).
* Image_Tools_Border API version.
* Function which called before render.
* @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 )
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_resultImage');
$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')
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_resultImage');
// 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.
* Draw a line around an image
* Draw a line around an image. If $offset is 0, the line is just around the image.
* If $offset is positive, the line is outside the image, and the gad is filled with background color.
* If $offset is -width / 2, the line is centered on the border of the image.
* If $offset is -$width, the line in just inside the image.
* If $offset is negative, the line is inside the image.
* @param int $width Line width
* @param mixed $color Line color
* @param int $offset Distance between line and image.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
* @author Charles Brunet <charles.fmj@gmail.com>
function _line ($width = 2 , $color = '000000', $offset = 0 , $background = 'FFFFFF')
// Agrandir l'image si nécessaire
$w= $this->_iWidth + (2 * $mag);
$h= $this->_iHeight + (2 * $mag);
// Create the target image
return PEAR ::raiseError ('Cannot initialize new GD image stream');
$background = imagecolorallocate($target, $background['r'], $background['g'], $background['b']);
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_resultImage');
$a = ($mag < 0 )?0- $mag:0;
for ($i= $a; $i< $a+ $width; ++ $i) {
* This method is useless, use directly call for specific border style
* @return TRUE|PEAR_Error
$callback = array ($this, " _{$this->options['style']}" );
return PEAR ::raiseError ('Invalid border style or not supported');
* c-hanging-comment-ender-p: nil
Documentation generated on Mon, 26 May 2008 06:30:08 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|