Source for file Marquee.php
Documentation is available at Marquee.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
* This is a driver file contains the Image_Tools_Marquee 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: Marquee.php,v 1.2 2006/11/23 22:17:31 firman Exp $
* Load Image_Tools as the base class.
require_once 'Image/Tools.php';
* Image_Tools_Marquee rectangle marquee.
* @name IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE
define('IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE', 'marquee_rectangle');
* Image_Tools_Marquee single column marquee.
* @name IMAGE_TOOLS_MARQUEE_TYPE_SINGLECOL
define('IMAGE_TOOLS_MARQUEE_TYPE_SINGLECOL', 'marquee_singlecol');
* Image_Tools_Marquee single row marquee.
* @name IMAGE_TOOLS_MARQUEE_TYPE_SINGLEROW
define('IMAGE_TOOLS_MARQUEE_TYPE_SINGLEROW', 'marquee_singlerow');
* Image_Tools_Marquee polygon marquee.
* Notes: this constant is useless at this time.
* @name IMAGE_TOOLS_MARQUEE_TYPE_POLYGON
define('IMAGE_TOOLS_MARQUEE_TYPE_POLYGON', 'marquee_polygon');
// {{{ Class: Image_Tools_Marquee
* This class provide marquee extraction 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
* sample mixed Sample image, a GD image resource or string filename.
* x int X position, this sets X position where marquee will be
* y int Y position, this sets Y position where marquee will be
'image' => null , // Destination image.
'sample' => null , // Sample image.
* Available options for Image_Tools_Marquee.
* Available methods for Image_Tool_Marquee (only public methods).
'setRectangleMarquee' => array (
'setSingleColMarquee' => array (
'setSingleRowMarquee' => array (
* Image_Tools_Marquee 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)) {
if (PEAR ::isError ($res)) {
// {{{ setRectangleMarquee()
* Set marquee using rectangle.
* @param int $topLeftX Top left x coordinate.
* @param int $topLeftY Top left y coordinate.
* @param int $bottomRightX Bottom right x coordinate.
* @param int $bottomRightY Bottom right y coordinate.
* @return bool Always TRUE.
$bottomRightX, $bottomRightY)
if ($topLeftX > $bottomRightX) {
$topLeftX = $bottomRightX;
if ($topLeftY > $bottomRightY) {
$topLeftY = $bottomRightY;
$points = array ($topLeftX, $topLeftY, $bottomRightX, $bottomRightY);
// {{{ setSingleColumnMarquee()
* Set marquee using single column marquee.
* @param int $x X coordinate.
* @return bool Always TRUE.
$this->_setMarquee (IMAGE_EXTRACT_MARQUEE_TYPE_SINGLECOL , $x);
// {{{ setSingleRowMarquee()
* Set marquee using single row marquee.
* @param int $y Y coordinate.
* @return bool Always TRUE.
* @see Image_Tools_Marquee::_setMarquee()
$this->_setMarquee (IMAGE_EXTRACT_MARQUEE_TYPE_SINGLEROW , $y);
* Draw extraction result to resource.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
* @see Image_Tools_Marquee::_extractRectangle(),
* Image_Tools_Marquee::_extractSingleCol(),
* Image_Tools_Marquee::_extractSingleRow()
if (PEAR ::isError ($res)) {
return PEAR ::raiseError ('Invalid image resource Image_Tools_Mask::$_resultImage');
switch ($this->_marquee['type']) {
$this->_extractSingleColumn ($this->resultImage, $x, $y);
* Set marquee informations.
* @param string $type Marquee type. Use marquee type defined constants.
* @param mixed $points Marquee coordinate points.
function _setMarquee ($type, $points)
// {{{ _extractRectangle()
* Extract sample image using rectangle marquee and
* draw it on destination image.
* @param resource $img GD image resource.
* @param int $dstX Top left x coordinate.
* @param int $dstY Top left y coordinate.
function _extractRectangle (&$img, $dstX, $dstY)
$srcX = $this->_marquee['points'][0 ];
$srcY = $this->_marquee['points'][1 ];
$srcW = $this->_marquee['points'][2 ] - $srcX;
$srcH = $this->_marquee['points'][3 ] - $srcY;
$dstX, $dstY, $srcX, $srcY,
// {{{ _extractSingleColumn()
* Extract sample image using single column marquee and
* draw it on destination image.
* @param resource $img GD image resource.
* @param int $dstX Top left x coordinate.
* @param int $dstY Top left y coordinate.
function _extractSingleColumn (&$img, $dstX, $dstY)
$srcX = $this->_marquee['points'];
$dstX, $dstY, $srcX, $srcY,
// {{{ _extractSingleRow()
* Extract sample image using single column marquee and
* draw it on destination image.
* @param resource $img GD image resource.
* @param int $dstX Top left x coordinate.
* @param int $dstY Top left y coordinate.
function _extractSingleRow (&$img, $dstX, $dstY)
$srcY = $this->_marquee['points'];
$dstX, $dstY, $srcX, $srcY,
* c-hanging-comment-ender-p: nil
Documentation generated on Thu, 23 Nov 2006 18:00:06 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|