Source for file Watermark.php
Documentation is available at Watermark.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
* This is a driver file contains the Image_Tools_Watermark class
* Copyright (c) 2008 Charles Brunet <charles.fmj@gmail.com>
* 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 Charles Brunet <charles.fmj@gmail.com>
* @copyright Copyright (c) 2008 Charles Brunet <charles.fmj@gmail.com>
* @license http://www.opensource.org/licenses/bsd-license.php
* @since File available since Release 1.0.0RC1
require_once 'Image/Tools.php';
define('IMAGE_TOOLS_WATERMARK_POSITION_LEFT', 0 );
define('IMAGE_TOOLS_WATERMARK_POSITION_CENTER', 1 );
define('IMAGE_TOOLS_WATERMARK_POSITION_RIGHT', 2 );
define('IMAGE_TOOLS_WATERMARK_POSITION_TOP', 0 );
define('IMAGE_TOOLS_WATERMARK_POSITION_MIDDLE', 1 );
define('IMAGE_TOOLS_WATERMARK_POSITION_BOTTOM', 2 );
// {{{ Class: Image_Tools_Watermark
* This class provide a tool to add a little logo on an image
* @author Charles Brunet <charles.fmj@gmail.com>
* @copyright Copyright (c) 2008 Charles Brunet <charles.fmj@gmail.com>
* @license http://www.opensource.org/licenses/bsd-license.php
* @version Release: 1.0.0RC1
* @since Class available since Release 1.0.0RC1
* image mixed Destination image, a filename or an image string data or a GD image resource
* logo mixed Source logo, a filename or an image string data or a GD image resource
* width int Width of logo; 0 to keep original width
* height int Height of logo; 0 to keep original height
* marginx int Horizontal margin from the border of the image
* marginy int Vertical margin from the border of the image
* horipos number Horizontal position of the logo on destination image
* vertpos number Vertical position of the logo on destination image
* blend string Blending mode to use on composite operation, see
* Image_Tools_Blend of the supported blend mode. Default
'horipos' => IMAGE_TOOLS_WATERMARK_POSITION_RIGHT ,
'vertpos' => IMAGE_TOOLS_WATERMARK_POSITION_BOTTOM ,
* Available options for Image_Tools_Watermark
* Image_Tools_Watermark API version.
* Resource of source image.
* Resource of mark image.
* Function which called before render.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
* @see Image_Tools::createImage()
// Create the source image
if (PEAR ::isError ($source)) {
$this->_source = $source;
if (PEAR ::isError ($mark)) {
// includes the Image_Tools_Blend if blend mode enable
if ($this->options['blend'] != 'none') {
require_once 'Image/Tools/Blend.php';
* Draw image with logo result to resource.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
} else if ($this->options['width'] == 0 ) {
} else if ($this->options['height'] == 0 ) {
// calculates the x position
switch ($this->options['horipos']) {
// calculates the y position
switch ($this->options['vertpos']) {
// Create the target image
if ($MH != $this->options['height'] && $MW != $this->options['width']) {
$mark, $this->_mark, 0 , 0 , 0 , 0 ,
$mark, $this->_mark, 0 , 0 , 0 , 0 ,
if ($this->options['blend'] != 'none') {
$blend->set ('image1', $this->_source);
$blend->set ('image2', $this->_mark);
$blend->set ('mode', $this->options['blend']);
// applies the blending mode.
$this->_source = $blend->getResultImage ();
$result = imagecopy($this->_source, $this->_mark, $posx, $posy, 0 , 0 , $MW, $MH);
return PEAR ::raiseError ('Cannot copy logo image');
* c-hanging-comment-ender-p: nil
Documentation generated on Mon, 26 May 2008 06:30:16 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|