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-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: Swap.php,v 1.2 2006/11/23 22:17:31 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 masking tool for manipulating 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.
* 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.
* Initialize some internal variables.
* @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.
if (PEAR ::isError ($res)) {
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 Thu, 23 Nov 2006 18:00:08 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|