Source for file Swap.php
Documentation is available at Swap.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
* This is a driver file contains the Image_Tools_Swap 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: Swap.php,v 1.4 2008/05/26 06:15:17 firman Exp $
* Load Image_Tools as the base class.
require_once 'Image/Tools.php';
* Load PHP_Compat for PHP5 backward compalitiby function (str_split())
require_once 'PHP/Compat.php';
// load str_split() function
@PHP_Compat ::loadFunction ('str_split');
// {{{ Class: Image_Tools_Swap
* This class provide swap tool for manipulating an image.
* @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 Release: 1.0.0RC1
* image mixed Destination image, a filename or an image string
* data or a GD image resource.
* format string Destination color format (mix 'R', 'G', 'B'),
* only 5 variations (RBG, BGR, BRG, GRB, GBR)
* Available options for Image_Tools_Swap.
* Available methods for Image_Tool_Swap (only public methods).
* Image_Tools_Swap API version.
* Function which called before render.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
* @see Image_Tools::createImage()
if (PEAR ::isError ($res)) {
* Apply swap color to image and output result.
* This function swap channel color 'R', 'G', 'B' to set format.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_resultImage');
return PEAR ::raiseError ('Invalid swap format');
for ($x = 0; $x < $width; $x++ ) {
for ($y = 0; $y < $height; $y++ ) {
* Swap RGB color channel.
* This function swap color channel array to given format,
* e.g RGB->RBG mean red->red, green->blue and blue->green.
* @param string $format Swap format, mix 'R', 'G' and 'B' to other string.
* @param array $rgb RGB color, an array contains keys
* - red, green and blue, or
* @return array|PEAR_ErrorSwapped color channel, an array contains
* keys r, g and b on success or PEAR_Error
return PEAR ::raiseError ('Type mismatch for argument 2');
if (isset ($rgb['red']) && isset ($rgb['green']) && isset ($rgb['blue'])) {
$color['r'] = $rgb['red'];
$color['g'] = $rgb['green'];
$color['b'] = $rgb['blue'];
} elseif (isset ($rgb['r']) && isset ($rgb['g']) && isset ($rgb['b'])) {
} elseif (isset ($rgb[0 ]) && isset ($rgb[1 ]) && isset ($rgb[2 ])) {
return PEAR ::raiseError ('Invalid RGB color');
$format[0 ] => $color['r'],
$format[1 ] => $color['g'],
$format[2 ] => $color['b']
* c-hanging-comment-ender-p: nil
Documentation generated on Mon, 26 May 2008 06:30:11 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|