Source for file Mask.php
Documentation is available at Mask.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
* This is a driver file contains the Image_Tools_Mask 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: Mask.php,v 1.4 2008/05/26 06:32:15 firman Exp $
require_once 'Image/Tools.php';
* Notes: conflict with Image_Color v1.0.0
require_once 'Image/Color.php';
// {{{ Class: Image_Tools_Mask
* This class provide masking 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.
* mask mixed Mask image, a filename or an image string
* data or a GD image resource.
* sample mixed Sample image, a filename or an image string
* data or a GD image resource.
* mask_color mixed Mask color, use string for hexa color format or
* array contains 3 indexes 0 for RGB format
* unmask_color mixed Mask color, use string for hexa color format or
* array contains 3 indexes 0 for RGB format
* antialias bool Flag whether attempt to draw antialias mask
* antialias_factor int Antialias factor, this setting for antialias
'image' => null , // Destination image.
'mask' => null , // Mask image.
'sample' => null , // Sample image.
'mask_color' => '000000', // Mask color.
'unmask_color' => 'ffffff', // Unmask color.
'antialias' => true , // Antialias flag.
'antialias_factor' => 16 // Antialias factor.
* Available options for Image_Tools_Mask.
'unmask_color' => 'mixed',
'antialias_factor' => 'int'
* There is no public methods in Image_Tool_Mask.
* Image_Tools_Mask API version.
* GD image resource for mask image.
* GD image resource for sample image.
* Function which called before render.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
* @see Image_Tools::createImage()
if (PEAR ::isError ($res)) {
$this->_maskImage = $res;
if (PEAR ::isError ($res)) {
$this->_sampleImage = $res;
if (PEAR ::isError ($res)) {
* This function scan for mask color and closes colors position, grab color
* at found the position on sample image, then set the pixel color at the same
* position on destination image.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
* @see Image_Tools_Mask::_getNearestColors()
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_maskImage');
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_sampleImage');
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_resultImage');
$maskWidth = imagesx($this->_maskImage);
$maskHeight = imagesy($this->_maskImage);
$sampleWidth = imagesx($this->_sampleImage);
$sampleHeight = imagesy($this->_sampleImage);
$closesColors = $this->_getNearestColors ();
$closesColors = array ($this->options['maskColor']);
// scan for mask color or closes colors position
for ($x = 0; $x < $maskWidth; $x++ ) {
for ($y = 0; $y < $maskHeight; $y++ ) {
if ($x >= $sampleWidth || $y >= $sampleHeight) {
// grab color at x, y and convert to hex color format
// check color in closes colors collection
if (in_array($maskColor, $closesColors)) {
// grab color at x, y from sample image
// allocate color on destination image
// set a pixel color at destination image
* Get nearest colors between mask color and unmask color using
* @return array Colors range.
function _getNearestColors ()
$imcolor = new Image_Color;
$imcolor->setColors ($this->options['mask_color'], $this->options['unmask_color']);
return $imcolor->getRange ($this->options['antialias_factor']);
* 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.
|