cvs: pear /Image_Tools generate_package_xml.php package.xml package2.xml /Image_Tools/Image Tools.php /Image_Tools/Image/Tools Border.php
Marquee.php Mask.php Swap.php /Image_Tools/docs readme.txt /Image_Tools/docs/examples border.php marquee.php mask.php swap.php
/Image_Tools/docs/examples/images mask.png master.PNG pear.PNG
| From: | Firman Wandayandi | Date: | Sun, 02 Oct 2005 17:53:01 +0000 |
| Subject: | cvs: pear /Image_Tools generate_package_xml.php package.xml package2.xml /Image_Tools/Image Tools.php /Image_Tools/Image/Tools Border.php Marquee.php Mask.php Swap.php /Image_Tools/docs readme.txt /Image_Tools/docs/examples border.php marquee.php mask.php swap.php /Image_Tools/docs/examples/images mask.png master.PNG pear.PNG |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35228@lists.php.net to get a copy of this message | ||
firman Sun Oct 2 13:53:01 2005 EDT
Added files:
/pear/Image_Tools/Image/Tools Marquee.php Mask.php Swap.php
/pear/Image_Tools package2.xml
/pear/Image_Tools/docs/examples border.php marquee.php mask.php
swap.php
/pear/Image_Tools/docs/examples/images mask.png master.PNG pear.PNG
/pear/Image_Tools/docs readme.txt
Modified files:
/pear/Image_Tools/Image Tools.php
/pear/Image_Tools/Image/Tools Border.php
/pear/Image_Tools generate_package_xml.php package.xml
Log:
New Image_Tools's API and added some feature files also package2
http://cvs.php.net/diff.php/pear/Image_Tools/Image/Tools.php?r1=1.3&r2=1.4&ty=u Index: pear/Image_Tools/Image/Tools.php diff -u pear/Image_Tools/Image/Tools.php:1.3 pear/Image_Tools/Image/Tools.php:1.4 --- pear/Image_Tools/Image/Tools.php:1.3 Wed Feb 23 07:16:08 2005 +++ pear/Image_Tools/Image/Tools.php Sun Oct 2 13:52:56 2005 @@ -1,45 +1,63 @@ <?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +// {{{ Header /** - * Image_Tools. - * - * This is the main file of the Image_Tools package. This file has to be - * included for usage of Image_Tools. + * This is a main file of Image_Tools package. * * PHP versions 4 and 5 * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. - * - * @category Image - * @package Tools - * @author Tobias Schlitt <toby@php.net> - * @copyright 1997-2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Tools.php,v 1.3 2005/02/23 12:16:08 toby Exp $ - * @link http://pear.php.net/package/Net_FTP2 - * @since File available since Release 0.0.1 + * LICENSE: + * + * The PHP License, version 3.0 + * + * Copyright (c) 1997-2005 The PHP Group + * + * This source file is subject to version 3.0 of the PHP license, + * that is bundled with this package in the file LICENSE, and is + * available through the world-wide-web at the following url: + * http://www.php.net/license/3_0.txt. + * If you did not receive a copy of the PHP license and are unable to + * obtain it through the world-wide-web, please send a note to + * license@php.net so we can mail you a copy immediately. + * + * @category Images + * @package Image_Tools + * @author Tobias Schlitt <toby@php.net> + * @author Firman Wandayandi <firman@php.net> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt + * The PHP License, version 3.0 + * @version CVS: $Id: Tools.php,v 1.4 2005/10/02 17:52:56 firman Exp $ */ - + +// }}} +// {{{ Dependencies /** - * Require PEAR file for error handling. + * load PEAR for error handling. */ require_once 'PEAR.php'; /** - * Require PHP_Compat for PHP5 compatibility (is_a()) + * load PHP_Compat for PHP backward compatibility. */ require_once 'PHP/Compat.php'; +/** + * is_a(), since PHP 4.2.0 + */ @PHP_Compat::loadFunction('is_a'); + +/** + * image_type_to_mime_type, since PHP 4.3.0 + */ @PHP_Compat::loadFunction('image_type_to_mime_type'); +// }}} +// {{{ Constants + /** * Image_Tools error, indicating that the given tool was not found. * @@ -69,7 +87,7 @@ /** * Image_Tools error, indicating that the given option was of a wrong type. * - * @name IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE + * @name IMAGE_TOOLS_BASE_ERR_OPTION_INVALID * @access public */ define('IMAGE_TOOLS_BASE_ERR_OPTION_INVALID', -4); @@ -140,7 +158,7 @@ define('IMAGE_TOOLS_BASE_ERR_NONSTATIC_FAILED', -11); /** - * Image_Tools error, indicating that you called a static method + * Image_Tools error, indicating that you called a static method * statically, which may only be called non statically. * * @name IMAGE_TOOLS_BASE_ERR_STATIC_FAILED @@ -148,24 +166,27 @@ */ define('IMAGE_TOOLS_BASE_ERR_STATIC_FAILED', -12); +// }}} +// {{{ Class: Image_Tools + /** * This is the Image_Tools base class * Every image-tool has to derive from this class and implement several methods * itself. Other methods are implemented in the base class directly, but may - * only be called on the sub-classes. The only method being called directly from the - * base class is the factory() method. + * only be called on the sub-classes. The only method being called directly from + * the base class is the factory() method. * - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @category Image - * @package Tools - * @author Tobias Schlitt <toby@php.net> - * @copyright 1997-2005 The PHP Group - * @version Release: @package_version@ - * @link http://pear.php.net/package/Net_FTP - * @since 0.0.1 - * @access public + * @category Images + * @package Image_Tools + * @author Tobias Schlitt <toby@php.net> + * @author Firman Wandayandi <firman@php.net> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt + * The PHP License, version 3.0 + * @version Release: @package_version@ */ class Image_Tools { + // {{{ Properties /** * Contain the options inside all subclasses. @@ -232,7 +253,18 @@ * @access protected */ var $apiVersion = '0.1'; - + + /** + * Result rendered image. + * + * @var resource + * @access protected + */ + var $resultImage = null; + + // }}} + // {{{ Constructor + /** * Constructor * @@ -245,12 +277,20 @@ * @see IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FORBIDEN */ function Image_Tools($options = array()) - { + { + PEAR::setErrorHandling(PEAR_ERROR_TRIGGER); if (is_a($this, 'Image_Tools') && !is_subclass_of($this, 'Image_Tools')) { - $this =& PEAR::raiseError('Cannot instanciate Image_Tools directly', IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FORBIDEN); + PEAR::raiseError('Cannot instanciate Image_Tools directly', + IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FORBIDEN); } + + $this->set($options); + PEAR::setErrorHandling(PEAR_ERROR_RETURN); } + // }}} + // {{{ factory() + /** * Create a new instance of an image tool * @@ -264,41 +304,55 @@ * @return object New image tool on success or PEAR_Error on failure * @access public * @static - * @see IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED, IMAGE_TOOLS_BASE_ERR_CLASS_INVALID, IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED + * @see IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED, + * IMAGE_TOOLS_BASE_ERR_CLASS_INVALID, + * IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, + * IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED */ function &factory($tool, $options = array()) { if (isset($this)) { - return PEAR::raiseError('This method may only be called statically', IMAGE_TOOLS_BASE_ERR_NONSTATIC_FAILED); + return PEAR::raiseError('This method may only be called statically', + IMAGE_TOOLS_BASE_ERR_NONSTATIC_FAILED); } + // Renice the tool name $toolParts = @explode('_', $tool); if (empty($toolParts) || !is_array($toolParts)) { $toolParts[] = $tool; } - array_walk($toolParts, ucfirst); + + foreach ($toolParts as $key => $value) { + $toolParts[$key] = ucfirst($value); + } $tool = implode('_', $toolParts); $toolPath = 'Image/Tools/'.$tool.'.php'; - + // Include the tool class - @require($toolPath); - - $className = "Image_Tools_${tool}.php"; + require_once($toolPath); + + $className = "Image_Tools_${tool}"; if (!class_exists($className)) { - return PEAR::raiseError('File not found '.$toolPath.' or undifined class '.$className, IMAGE_TOOLS_BASE_ERR_CLASS_INVALID); + return PEAR::raiseError('File not found ' . $toolPath . + ' or undefined class '.$className, + IMAGE_TOOLS_BASE_ERR_CLASS_INVALID); } - @$obj =& new $classname($options); + @$obj =& new $className($options); if (!is_object($obj) || !is_a($obj, $className)) { - return PEAR::raiseError('Could not instanciate image tool '.$className, IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED); + return PEAR::raiseError('Could not instanciate image tool '.$className, + IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED); } - $res = $obj->setOption($options); + $res = $obj->set($options); if (PEAR::isError($res)) { return $res; } return $obj; } + // }}} + // {{{ set() + /** * Set the option(s) * Set a single or multiple options. The parameter of that method may @@ -311,16 +365,18 @@ * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure * @access protected - * @see IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED + * @see IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, + * IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED */ function set($option, $value = null) { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } if (is_array($option)) { foreach ($option as $key => $value) { - $res = $this->setOption($key, @$value); + $res = $this->set($key, @$value); if (PEAR::isError($res)) { return $res; } @@ -334,7 +390,10 @@ $this->options[$option] = $value; return true; } - + + // }}} + // {{{ isValidOption() + /** * Has the option a valid value? * Determines, if the value given is valid for the option. @@ -344,7 +403,8 @@ * * @return bool|PEAR_Error TRUE on acceptans or PEAR_Error on failure * @access protected - * @see IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED + * @see IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, + * IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED */ function isValidOption($name, $value) @@ -355,7 +415,7 @@ } $type = $this->availableOptions[$name]; switch ($type) { - case 'mixed': + case 'mixed': return true; break; case 'bool': @@ -382,24 +442,34 @@ } break; } - return PEAR::raiseError('Wrong type for option '.$name.'. Requires '.$type.', but is '.gettype($value), IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE); + return PEAR::raiseError('Wrong type for option ' . $name . + '. Requires '. $type .', but is ' . gettype($value), + IMAGE_TOOLS_BASE_ERR_OPTION_INVALID); } - + + // }}} + // {{{ get() + /** * Get the value of the option * - * returns the value of an option of, an error if the option is not available. + * returns the value of an option of, an error if the option is not + * available. * * @param string $option Option name. * - * @return mixed|PEAR_Error Option value on success or PEAR_Error on failure. + * @return mixed|PEAR_Error Option value on success or + * PEAR_Error on failure. * @access public - * @see IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED, IMAGE_TOOLS_BASE_ERR_OPTION_NOTSET, IMAGE_TOOLS_BASE_ERR_STATIC_FAILED + * @see IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED, + * IMAGE_TOOLS_BASE_ERR_OPTION_NOTSET, + * IMAGE_TOOLS_BASE_ERR_STATIC_FAILED */ function get($option) { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } $res = $this->supportsOption($option); if (PEAR::isError($res)) { @@ -408,9 +478,128 @@ if (isset($this->options[$option])) { return $this->options[$option]; } - return PEAR::raiseError('Option '.$option.' not set', IMAGE_TOOLS_BASE_ERR_OPTION_NOTSET); + return PEAR::raiseError('Option '.$option.' not set', + IMAGE_TOOLS_BASE_ERR_OPTION_NOTSET); + } + + // }}} + // {{{ createImageFromFile() + + /** + * Create a GD image resource from file (JPEG, PNG, WBMP and XBM support). + * + * @param string $filename The image filename. + * + * @return mixed GD image resource on success, PEAR_Error on failure. + * @access public + * @static + */ + function createImageFromFile($filename) + { + if (!is_file($filename) || !is_readable($filename)) { + return PEAR::raiseError('Unable to open file "' . $filename . '"'); + } + + // determine image format + list( , , $imgType) = getimagesize($filename); + + switch ($imgType) { + case IMAGETYPE_JPEG: + return imagecreatefromjpeg($filename); + break; + case IMAGETYPE_PNG: + return imagecreatefrompng($filename); + break; + case IMAGETYPE_WBMP: + return imagecreatefromwbmp($filename); + break; + case IMAGETYPE_XBM: + return imagecreatefromxbm($filename); + break; + default: + return PEAR::raiseError('Unsupport image type'); + } + } + + // }}} + // {{{ createImageFromString() + + /** + * Create a GD image resource from a string data. + * + * @param string $data The string image data. + * + * @return mixed GD image resource on success, PEAR_Error on failure. + * @access public + * @static + */ + function createImageFromString($data) + { + if (!is_string($data) || empty($data)) { + PEAR::raiseError('Invalid data value.'); + } + + $img = imagecreatefromstring($data); + if ($img === false) { + return PEAR::raiseError('Failed to create image from string data'); + } + return $img; + } + + // }}} + // {{{ createImage() + + /** + * Create a GD image resource from given input. + * + * This method tried to detect what the input, if it is a file the + * createImageFromFile will be called, otherwise createImageFromString(). + * + * @param mixed $input The input for creating an image resource. The value + * may a string of filename, string of image data or + * GD image resource. + * + * @return resource|PEAR_Error An GD image resource on success or + * PEAR_Error on failure. + * @access public + * @see createImageFromFile() + * @see createImageFromString() + */ + function createImage($input) + { + if (is_file($input)) { + return Image_Tools::createImageFromFile($input); + } else if (is_string($input)) { + return Image_Tools::createImageFromString($input); + } else if (Image_Tools::isGDImageResource($input)) { + return $input; + } + return PEAR::raiseError('Invalid input given.'); } + // }}} + // {{{ isGDImageResource() + + /** + * Find the whether a value is the GD image resource or not. + * + * @param mixed $value Value to evaluate. + * + * @return bool TRUE if a value is the GD image resource, otherwise FALSE. + * @access public + * @static + */ + function isGDImageResource($value) + { + if (is_resource($value) && get_resource_type($value) == 'gd') { + return true; + } + return false; + } + + // }}} + // {{{ render() + /** * Render the result of a tool to the given image * @@ -419,92 +608,129 @@ * method gets a GD2 image as it's parameter. The creation of images inside * Image_Tools is not supported. * - * @param resource $img GD image resource * @access protected * @see IMAGE_TOOLS_BASE_ERR_STATIC_FAILED */ - function render (&$img) + function render() { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } } + // }}} + // {{{ getResultImage() + + /** + * Get rendered image. + * + * @return resource The GD image resource of rendered result. + * @access public + */ + function getResultImage() + { + return $this->resultImage; + } + + // }}} + // {{{ display() + /** * Display rendered image (send it to browser). * This method is a common implementation to render and output an image. * The method calls the render() method automatically and outputs the * image to the browser. * - * @param resource $image GD image resource. - * @param int $type optional Type of format image (use defined image type constants), - * default is IMAGETYPE_PNG. + * @param int $type optional Type of format image (use defined image + * type constants), default is IMAGETYPE_PNG. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. - * @access protected - * @see IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED, IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED + * @access public + * @see IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED, + * IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED */ - function display(&$image, $type = IMAGETYPE_PNG) + function display($type = IMAGETYPE_PNG) { + $res = $this->render(); + if (PEAR::isError($res)) { + return PEAR::raiseError('Error rendering: ' . $resultImage->getMessage()); + } + $ctype = image_type_to_mime_type($type); if (!headers_sent()) { header('Content-Type: ' . $ctype); } else { - PEAR::raiseError('Headers have already been sent. Could not display image.', IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED); + return PEAR::raiseError('Headers have already been sent. Could not display image.', + IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED); } switch ($type) { case IMAGETYPE_PNG: - imagepng($this->render($image)); + imagepng($this->resultImage); break; case IMAGETYPE_JPEG: - imagejpeg($this->render($image)); + imagejpeg($this->resultImage); break; case IMAGETYPE_WBMP: - imagewbmp($this->render($image)); + imagewbmp($this->resultImage); break; default: - return PEAR::raiseError('Image type '.$ctype.' not supported by PHP', IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED); + return PEAR::raiseError('Image type '.$ctype.' not supported by PHP', + IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED); break; } return true; } + // }}} + // {{{ save() + /** * Save rendered image to a file. * - * @param resource $image GD image resource. * @param string $path Path to destination filename. - * @param int $type optional Type of image format (use defined image type constants), - * default is IMAGETYPE_PNG. + * @param int $type optional Type of image format (use defined image type + * constants), default is IMAGETYPE_PNG. * * @return bool|PEAR_Error TRUE on success, PEAR_Error on failure. - * @access protected - * @see IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED, IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED + * @access public + * @see IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED, + IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED */ - function save(&$image, $path, $type = IMAGETYPE_PNG) + function save($path, $type = IMAGETYPE_PNG) { + $res = $this->render(); + if (PEAR::isError($res)) { + return PEAR::raiseError('Error rendering: ' . $resultImage->getMessage()); + } + switch ($type) { case IMAGETYPE_PNG: - $res = imagepng($this->render($image), $path); + $res = imagepng($this->resultImage, $path); break; case IMAGETYPE_JPEG: - $res = imagejpeg($this->render($image), $path); + $res = imagejpeg($this->resultImage, $path); break; case IMAGETYPE_WBMP: - $res = imagewbmp($this->render($image), $path); + $res = imagewbmp($this->resultImage, $path); break; default: - return PEAR::raiseError('Image type '.$ctype.' not supported by PHP', IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED); + return PEAR::raiseError('Image type '.$ctype.' not supported by PHP', + IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED); break; } if (!$res) { - PEAR::raiseError('Saving image '.$path.' failed', IMAGE_TOOLS_BASE_ERR_SAVEIMAGE_FAILED); + PEAR::raiseError('Saving image '.$path.' failed', + IMAGE_TOOLS_BASE_ERR_SAVEIMAGE_FAILED); } return true; } + // }}} + // {{{ supportsOption() + /** * Find out the whether a subclass supports the option * @@ -512,19 +738,25 @@ * * @return bool TRUE if supported, otherwise FALSE * @access protected - * @see IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED, IMAGE_TOOLS_BASE_ERR_STATIC_FAILED + * @see IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED, + * IMAGE_TOOLS_BASE_ERR_STATIC_FAILED */ function supportsOption($option) { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } - if (in_array($option, $this->availableOptions)) { + if (isset($this->availableOptions[$option])) { return true; } - return PEAR::raiseError('Unsupported option '.$option, IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED); + return PEAR::raiseError('Unsupported option '.$option, + IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED); } + // }}} + // {{{ availableOptions() + /** * Get all available options of the subclass * @@ -535,11 +767,15 @@ function availableOptions() { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } return $this->availableOptions; } + // }}} + // {{{ supportsMethod() + /** * Get the method parameters * @@ -553,14 +789,19 @@ function supportsMethod($methodName) { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } if (isset($this->availableMethods[$methodName])) { return $this->availableMethods[$methodName]; } - return PEAR::raiseError('Unsupported method '.$methodName, IMAGE_TOOLS_BASE_ERR_METHOD_UNSUPPORTED); + return PEAR::raiseError('Unsupported method '.$methodName, + IMAGE_TOOLS_BASE_ERR_METHOD_UNSUPPORTED); } + // }}} + // {{{ availableMethods() + /** * Get available methods * @@ -575,11 +816,15 @@ function availableMethods() { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } return $this->availableMethods; } + // }}} + // {{{ getAPIVersion() + /** * Get the API version of the common base * @@ -600,6 +845,9 @@ } } + // }}} + // {{{ getVersion() + /** * Get the subclass version. * @@ -608,7 +856,20 @@ */ function getVersion() { - return $this->version; + return $this->version; } + + // }}} } -?> + +// }}} + +/* + * Local variables: + * mode: php + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> \ No newline at end of file http://cvs.php.net/diff.php/pear/Image_Tools/Image/Tools/Border.php?r1=1.3&r2=1.4&ty=u Index: pear/Image_Tools/Image/Tools/Border.php diff -u pear/Image_Tools/Image/Tools/Border.php:1.3 pear/Image_Tools/Image/Tools/Border.php:1.4 --- pear/Image_Tools/Image/Tools/Border.php:1.3 Wed Feb 23 07:16:09 2005 +++ pear/Image_Tools/Image/Tools/Border.php Sun Oct 2 13:52:59 2005 @@ -1,158 +1,285 @@ <?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +// {{{ Header /** - * Image_Tools_Border. - * - * This file holds the implementation of the image tool Border. The file - * is included using the Image_Tools::factory() method. + * This is a driver file contains the Image_Tools_Border class. * * PHP versions 4 and 5 * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. - * - * @category Image - * @package Tools - * @author Tobias Schlitt <toby@php.net> - * @copyright 1997-2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Border.php,v 1.3 2005/02/23 12:16:09 toby Exp $ - * @link http://pear.php.net/package/Net_FTP2 - * @since File available since Release 0.0.1 + * LICENSE: + * + * The PHP License, version 3.0 + * + * Copyright (c) 1997-2005 The PHP Group + * + * This source file is subject to version 3.0 of the PHP license, + * that is bundled with this package in the file LICENSE, and is + * available through the world-wide-web at the following url: + * http://www.php.net/license/3_0.txt. + * If you did not receive a copy of the PHP license and are unable to + * obtain it through the world-wide-web, please send a note to + * license@php.net so we can mail you a copy immediately. + * + * @category Images + * @package Image_Tools + * @author Firman Wandayandi <firman@php.net> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt + * The PHP License, version 3.0 + * @version CVS: $Id: Border.php,v 1.4 2005/10/02 17:52:59 firman Exp $ */ +// }}} +// {{{ Dependencies + /** - * Require the base class. + * Load Image_Tools as the base class. */ require_once 'Image/Tools.php'; /** - * Image_Tools_Border. - * - * This image tool creates rectengular borders in images. + * Load Image_Color for color handling. + */ +require_once 'Image/Color.php'; + +// }}} +// {{{ Class: Image_Tools_Border + +/** + * This class provide border creation on an image. * - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @category Image - * @package Tools - * @author Tobias Schlitt <toby@php.net> - * @copyright 1997-2005 The PHP Group - * @version Release: @package_version@ - * @link http://pear.php.net/package/Net_FTP - * @since 0.0.1 - * @access public + * @category Images + * @package Image_Tools + * @author Firman Wandayandi <firman@php.net> + * @copyright Copyright (c) 2004-2005 Firman Wandayandi + * @license http://www.php.net/license/3_0.txt + * The PHP License, version 3.0 + * @version Release: @package_version@ */ -class Image_Tools_Border extends Image_Tools { +class Image_Tools_Border extends Image_Tools +{ + // {{{ Properties + + /** + * Border options: + * <pre> + * image mixed Destination image, a filename or an image string + * data or a GD image resource. + * </pre> + * + * @var array + * @access protected + */ + var $options = array( + 'image' => null // An image. + ); + + /** + * Available options for Image_Tools_Border. + * + * @var array + * @access protected + */ + var $availableOptions = array( + 'image' => 'mixed' + ); + + /** + * Available methods for Image_Tool_Border (only public methods). + * + * @var array + * @access protected + */ + var $availableMethods = array( + 'rounded' => array( + 'radius' => 'integer', + 'background' => 'mixed', + 'antiAlias' => 'integer' + ), + 'bevel' => array( + 'size' => 'integer', + 'highlight' => 'mixed', + 'shadow' => 'mixed' + ) + ); + + /** + * Image_Tools_Border API version. + * + * @var string + * @access protected + */ + var $version = '0.1'; + + /** + * Image width. + * + * @var int + * @access private + */ + var $_iWidth = 0; + + /** + * Image height. + * + * @var int + * @access private + */ + var $_iHeight = 0; + + // }}} + // {{{ _init() + /** + * Initialize some internal variables. + * + * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. + * @access private + */ + function _init() + { + $res = Image_Tools::createImage($this->options['image']); + if (PEAR::isError($res)) { + return $res; + } + + $this->resultImage = $res; + $this->_iWidth = imagesx($this->resultImage); + $this->_iHeight = imagesy($this->resultImage); + + return true; + } + + // }}} + // {{{ rounded() /** - * Configuration options - * - * @var array - */ - var $options = array ( 'x' => false, - 'y' => false, - 'width' => false, - 'height' => false, - 'fgColor' => false, - 'bgColor' => false, - 'lineWidth' => 1, - 'roundWidth' => 0); - - /** - * Constructor - * The constructor is normaly called in the factory method of the - * inherited class @see Image_Tools, where you can provide the options - * array, as follows: - * - * <pre> - * array( - * 'x' => top left corner x coordinate - * 'y' => top left corner y coordinate - * 'width' => width of the border - * 'height' => height of the border - * 'fgColor' => color of the border - * 'bgColor' => color of the background - * 'lineWidth' => thickness of the border, default is 1 - * 'roundWidth' => width of the edge rounding, default is no round - * ) - * </pre> - * - * @access public - * @param array $options Options as described above. - */ - function Image_Tools_Border ( $options = array() ) { - foreach ( $options as $option => $value) { - if (isset($this->options[$option])) { - $this->options[$option] = $value; + * Make an image be a rounded edge. + * + * @param int $radius optional Radius size. + * @param mixed $background Background color. + * @param int $antiAlias Anti-alias factor. + * + * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. + * @access public + */ + function rounded($radius = 3, $background = 'FFFFFF', $antiAlias = 3) + { + $res = $this->_init(); + if (PEAR::isError($res)) { + return $res; + } + + if (!Image_Tools::isGDImageResource($this->resultImage)) { + return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); + } + + $background = Image_Color::hex2rgb($background); + $antiAlias = min(3, $antiAlias); + + $iDot = imagecreate(1, 1); + imagecolorallocate($iDot, $background[0], $background[1], $background[2]); + + for ($i = 0 - $radius; $i <= $radius; $i++) { + $y = $i < 0 ? $i + $radius - 1 : $this->_iHeight - ($radius - $i); + for ($j = 0 - $radius; $j <= $radius; $j++) { + $x = $j < 0 ? $j + $radius - 1 : $this->_iWidth - ($radius - $j); + if ($i != 0 || $j != 0) { + $distance = round(sqrt(($i * $i) + ($j * $j))); + $opacity = $distance < $radius - $antiAlias ? + 0 : max(0, 100 - (($radius - $distance) * 33)); + $opacity = $distance > $radius ? 100 : $opacity; + imagecopymerge($this->resultImage, $iDot, $x, $y, 0, 0, 1, 1, $opacity); + } } } + + imagedestroy($iDot); + + return true; } + // }}} + // {{{ bevel() + /** - * Draw the border to the image - * This draws the configured border to the provided image. Beware, that - * every pixel inside the border clipping will be overwritten with the - * given background color. This will be changed in the next release. - * - * @access public - * @return void - */ - function draw ( ) { - $o = $this->options; - - $fgCol = imagecolorallocate($this->img, $o['fgColor']['r'], $o['fgColor']['g'], $o['fgColor']['b']); - $bgCol = imagecolorallocate($this->img, $o['bgColor']['r'], $o['bgColor']['g'], $o['bgColor']['b']); - - // FG - $startXfg = $o['x'] - $o['lineWidth']; - $startYfg = $o['y'] - $o['lineWidth']; - $endXfg = $o['x'] + $o['width'] + $o['lineWidth']; - $endYfg = $o['y'] + $o['height'] + $o['lineWidth']; - - $res = imagefilledrectangle($this->img, $startXfg, $startYfg, $endXfg, $endYfg, $fgCol); - - // BG: - $startXbg = $o['x']; - $startYbg = $o['y']; - $endXbg = $o['x'] + $o['width']; - $endYbg = $o['y'] + $o['height']; - - $res = imagefilledrectangle($this->img, $startXbg, $startYbg, $endXbg, $endYbg, $bgCol); - - if ($o['roundWidth'] > 0) { - - // Top left corner erase - $res = imagefilledrectangle($this->img, $startXfg, $startYfg, $startXfg + $o['roundWidth'] + $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], $bgCol); - // Bottom left corner erase - $res = imagefilledrectangle($this->img, $startXfg, $endYfg - $o['roundWidth'] - $o['lineWidth'], $startXfg + $o['roundWidth'] + $o['lineWidth'], $endYfg, $bgCol); - // Bottom right corner erase - $res = imagefilledrectangle($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], $endXfg, $endYfg, $bgCol); - // Top right corner erase - $res = imagefilledrectangle($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $startYfg, $endXfg, $startYfg + $o['roundWidth'] + $o['lineWidth'], $bgCol); - - // Top left corner arc - $res = imagefilledarc($this->img, $startXfg + $o['roundWidth'] + $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], ($o['roundWidth'] + $o['lineWidth']) * 2, ($o['roundWidth'] + $o['lineWidth']) * 2, 180, 270, $fgCol, IMG_ARC_PIE); - // Top right corner arc - $res = imagefilledarc($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], ($o['roundWidth'] + $o['lineWidth']) * 2, ($o['roundWidth'] + $o['lineWidth']) * 2, 270, 0, $fgCol, IMG_ARC_PIE); - // Bottom right corner arc - $res = imagefilledarc($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], ($o['roundWidth'] + $o['lineWidth']) * 2, ($o['roundWidth'] + $o['lineWidth']) * 2, 0, 90, $fgCol, IMG_ARC_PIE); - // Bottom left corner arc - $res = imagefilledarc($this->img, $startXfg + $o['roundWidth'] + $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], ($o['roundWidth'] + $o['lineWidth']) * 2, ($o['roundWidth'] + $o['lineWidth']) * 2, 90, 180, $fgCol, IMG_ARC_PIE); - - - // Top left corner arc - $res = imagefilledarc($this->img, $startXfg + $o['roundWidth'] + $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], $o['roundWidth'] * 2, $o['roundWidth'] * 2, 180, 270, $bgCol, IMG_ARC_PIE); - // Top right corner arc - $res = imagefilledarc($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], $o['roundWidth'] * 2, $o['roundWidth'] * 2, 270, 0, $bgCol, IMG_ARC_PIE); - // Bottom right corner arc - $res = imagefilledarc($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], $o['roundWidth'] * 2, $o['roundWidth'] * 2, 0, 90, $bgCol, IMG_ARC_PIE); - // Bottom left corner arc - $res = imagefilledarc($this->img, $startXfg + $o['roundWidth'] + $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], $o['roundWidth'] * 2, $o['roundWidth'] * 2, 90, 180, $bgCol, IMG_ARC_PIE); + * Make an image bevel border. + * + * @param int $size Border size. + * @param mixed $highlight Highlight color. + * @param mixed $shadow Shadow color. + * + * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. + * @access public + */ + function bevel($size = 8, $highlight = 'FFFFFF', $shadow = '000000') + { + $res = $this->_init(); + if (PEAR::isError($res)) { + return $res; + } + + if (!Image_Tools::isGDImageResource($this->resultImage)) { + return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); } + + $highlight = Image_Color::hex2rgb($highlight); + $shadow = Image_Color::hex2rgb($shadow); + + // Create an image resource for highlight. + $iLight = imagecreate($this->_iWidth, $this->_iHeight); + imagecolorallocate($iLight, $highlight[0], $highlight[1], $highlight[2]); + + // Create an image resource for shadow. + $iShadow = imagecreate(1, 1); + imagecolorallocate($iShadow, $shadow[0], $shadow[1], $shadow[2]); + + for ($j = 0; $j < $size; $j++) { + $opacity = 100 - (($j + 1) * (100 / $size)); + imagecopymerge($this->resultImage, $iLight, $j, $j, + 0, 0, 1, $this->_iHeight - (2 * $j), $opacity); + imagecopymerge($this->resultImage, $iLight, $j - 1, $j - 1, + 0, 0, $this->_iWidth - (2 * $j), 1, $opacity); + imagecopymerge($this->resultImage, $iShadow, $this->_iWidth - ($j + 1), $j, + 0, 0, 1, $this->_iHeight - (2 * $j), max(0, $opacity - 10)); + imagecopymerge($this->resultImage, $iShadow, $j, $this->_iHeight - ($j + 1), + 0, 0, $this->_iWidth - (2 * $j), 1, max(0, $opacity - 10)); + } + + // Free highlight and shadow image resources. + imagedestroy($iLight); + imagedestroy($iShadow); + + return true; } + + // }}} + // {{{ render() + + /** + * This method is useless, use directly call for specific border style + * method. + * + * @return bool always TRUE. + * @access protected + */ + function render() + { + return true; + } + + // }}} } -?> + +// }}} + +/* + * Local variables: + * mode: php + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> \ No newline at end of file http://cvs.php.net/diff.php/pear/Image_Tools/generate_package_xml.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Tools/generate_package_xml.php diff -u pear/Image_Tools/generate_package_xml.php:1.1 pear/Image_Tools/generate_package_xml.php:1.2 --- pear/Image_Tools/generate_package_xml.php:1.1 Wed Nov 12 18:11:42 2003 +++ pear/Image_Tools/generate_package_xml.php Sun Oct 2 13:52:59 2005 @@ -1,70 +1,73 @@ <?php +require_once('PEAR/PackageFileManager.php'); - $make = true; +$pkg = new PEAR_PackageFileManager; - echo ini_get('include_path'); +$packagedir = dirname(__FILE__); +$self = basename(__FILE__); - require_once('PEAR/PackageFileManager.php'); +$desc = "Tools collection of common image manipulations."; - $pkg = new PEAR_PackageFileManager; +$options = array( + 'simpleoutput' => true, + 'doctype' => 'D:\Net\www\htdocs\PEAR\PEAR\data\PEAR\package.dtd', + 'package' => 'Image_Tools', + 'license' => 'PHP License', + 'baseinstalldir' => '', + 'version' => '0.3.0', + 'packagedirectory' => $packagedir, + 'pathtopackagefile' => $packagedir, + 'state' => 'alpha', + 'filelistgenerator' => 'file', + 'notes' => 'Hurried release of Image_Tools in order to introduce new API and features', + 'summary' => 'Tools collection for images', + 'description' => $desc, + 'dir_roles' => array( + 'docs' => 'doc', + 'data' => 'data' + ), + 'ignore' => array( + 'package.xml', + '*.tgz', + $self + ) +); - // directory that PEAR CVS is located in - $cvsdir = '/cvs/pear/'; - $packagedir = $cvsdir . 'Image_Tools/'; - $category = 'Image'; - - $e = $pkg->setOptions( - array('baseinstalldir' => '', - 'version' => '0.2', - 'packagedirectory' => $packagedir, - 'pathtopackagefile' => $packagedir, - 'state' => 'alpha', - 'filelistgenerator' => 'cvs', - 'notes' => 'Promised design change. Image_Tools now implements - the factory pattern I promised on pear-dev.', - 'package' => 'Image_Tools', - 'dir_roles' => array( - 'doc' => 'doc'), - 'ignore' => array('package.xml'), - )); - - if (PEAR::isError($e)) { - echo $e->getMessage(); - exit; - } - - $e = $pkg->addDependency('gd', '2', 'has', 'ext'); - if (PEAR::isError($e)) { - echo $e->getMessage(); - exit; - } - - // hack until they get their shit in line with docroot role - $pkg->addRole('tpl', 'php'); - $pkg->addRole('png', 'php'); - $pkg->addRole('gif', 'php'); - $pkg->addRole('jpg', 'php'); - $pkg->addRole('css', 'php'); - $pkg->addRole('js', 'php'); - $pkg->addRole('ini', 'php'); - $pkg->addRole('inc', 'php'); - $pkg->addRole('afm', 'php'); - $pkg->addRole('pkg', 'doc'); - $pkg->addRole('cls', 'doc'); - $pkg->addRole('proc', 'doc'); - $pkg->addRole('sh', 'script'); - - if (isset($make)) { - $e = $pkg->writePackageFile(); - } else { - $e = $pkg->debugPackageFile(); - } - - if (PEAR::isError($e)) { - echo $e->getMessage(); - } - - if (!isset($make)) { - echo '<a href="' . $_SERVER['PHP_SELF'] . '?make=1">Make this file</a>'; - } +$e = $pkg->setOptions($options); +if (PEAR::isError($e)) { + echo $e->getMessage(); + die; +} + +// hack until they get their shit in line with docroot role +$pkg->addRole('tpl', 'php'); +$pkg->addRole('png', 'php'); +$pkg->addRole('gif', 'php'); +$pkg->addRole('jpg', 'php'); +$pkg->addRole('css', 'php'); +$pkg->addRole('js', 'php'); +$pkg->addRole('ini', 'php'); +$pkg->addRole('inc', 'php'); +$pkg->addRole('afm', 'php'); +$pkg->addRole('pkg', 'doc'); +$pkg->addRole('cls', 'doc'); +$pkg->addRole('proc', 'doc'); +$pkg->addRole('txt', 'doc'); +$pkg->addRole('sh', 'script'); + +$pkg->addMaintainer('toby', 'lead', 'Tobias', 'toby@php.net'); +$pkg->addMaintainer('neufeind', 'developer', 'Stefan Neufeind', 'pear.neufeind@speedpartner.de'); +$pkg->addMaintainer('firman', 'lead', 'Firman Wandayandi', 'firman@php.net'); + +$pkg->addDependency('PHP', '4.3.0', 'ge', 'php'); +$pkg->addDependency('PEAR', '1.3.3', 'ge', 'pkg'); +$pkg->addDependency('Image_Color', '1.0.1', 'ge', 'pkg'); +$pkg->addDependency('PHP_Compat', '1.4.1', 'ge', 'pkg'); + +$e = $pkg->addGlobalReplacement('package-info', '@package_version@', 'version'); + +$e = $pkg->writePackageFile(); +if (PEAR::isError($e)) { + echo $e->getMessage(); +} ?> http://cvs.php.net/diff.php/pear/Image_Tools/package.xml?r1=1.2&r2=1.3&ty=u Index: pear/Image_Tools/package.xml diff -u pear/Image_Tools/package.xml:1.2 pear/Image_Tools/package.xml:1.3 --- pear/Image_Tools/package.xml:1.2 Wed Nov 12 18:43:12 2003 +++ pear/Image_Tools/package.xml Sun Oct 2 13:53:00 2005 @@ -1,56 +1,121 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> +<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> -<package version="1.0"> - <name>Image_Tools</name> - <summary>Tool collection for images.</summary> - <description>A collection of comon image manipulations.</description> - <maintainers> - <maintainer> - <user>toby</user> - <name>Tobias Schlitt</name> - <email>tobias@schlitt.info</email> - <role>lead</role> - </maintainer> +<package version="1.0" packagerversion="1.4.1"> + <name>Image_Tools</name> + <summary>Tools collection for images</summary> + <description>Tools collection of common image manipulations. + </description> + <maintainers> + <maintainer> + <user>toby</user> + <name>Tobias</name> + <email>toby@php.net</email> + <role>lead</role> + </maintainer> + <maintainer> + <user>neufeind</user> + <name>Stefan Neufeind</name> + <email>pear.neufeind@speedpartner.de</email> + <role>developer</role> + </maintainer> + <maintainer> + <user>firman</user> + <name>Firman Wandayandi</name> + <email>firman@php.net</email> + <role>lead</role> + </maintainer> </maintainers> - <release> + <release> + <version>0.3.0</version> + <date>2005-10-02</date> + <license>PHP License</license> + <state>alpha</state> + <notes>Hurried release of Image_Tools in order to introduce new API and features + </notes> + <deps> + <dep type="ext" rel="has" version="2">gd</dep> + <dep type="php" rel="ge" version="4.3.0" optional="no"/> + <dep type="pkg" rel="ge" version="1.3.3" optional="no">PEAR</dep> + <dep type="pkg" rel="ge" version="1.0.1" optional="no">Image_Color</dep> + <dep type="pkg" rel="ge" version="1.4.1" optional="no">PHP_Compat</dep> + </deps> + <filelist> + <dir name="/" baseinstalldir=""> + <dir name="docs"> + <dir name="examples"> + <dir name="images"> + <file role="doc" name="mask.png"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="master.PNG"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="pear.PNG"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /docs/examples/images --> + <file role="doc" name="border.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="marquee.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="mask.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="swap.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /docs/examples --> + </dir> <!-- /docs --> + <dir name="Image"> + <dir name="Tools"> + <file role="php" name="Border.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Marquee.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Mask.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Swap.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /Image/Tools --> + <file role="php" name="Tools.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /Image --> + </dir> <!-- / --> + </filelist> + </release> + <changelog> + <release> + <version>0.1</version> + <date>2003-11-04</date> + <license>PHP License</license> + <state>alpha</state> + <notes>3rd try for initial release. All releases before were broken, so I decided to delete all of +them and start new with 0.1 + </notes> + </release> + <release> <version>0.2</version> <date>2003-11-13</date> <license>PHP License</license> <state>alpha</state> <notes>Promised design change. Image_Tools now implements - the factory pattern I promised on pear-dev.</notes> - <deps> - <dep type="ext" rel="has" version="2">gd</dep> - </deps> - <provides type="class" name="Image_Tools" /> - <provides type="function" name="Image_Tools::factory" /> - <provides type="function" name="Image_Tools::setOptions" /> - <provides type="function" name="Image_Tools::setImage" /> - <provides type="class" name="Image_Tools_Border" extends="Image_Tools" /> - <provides type="function" name="Image_Tools_Border::draw" /> - <filelist> - <file role="doc" baseinstalldir="" md5sum="e5931b3e458569abf90b8db58401081e" name="doc/readme.txt"/> - <file role="php" baseinstalldir="" md5sum="9b303992df68456e79cc886b0de44e89" name="Image/Tools.php"/> - <file role="php" baseinstalldir="" md5sum="076e3417d5412764509d054363cf982a" name="Image/Tools/Border.php"/> - <file role="php" baseinstalldir="" md5sum="b8aa85bfeb507b2dabb30ab0cf79861e" name="generate_package_xml.php"/> - </filelist> - </release> - <changelog> - <release> - <version>0.1</version> - <date>2003-11-04</date> - <license>PHP License</license> - <state>alpha</state> - <notes>3rd try for initial release. All releases before were broken, so I decided to delete all of -them and start new with 0.1</notes> - </release> - <release> - <version>0.2</version> - <date>2003-11-13</date> - <license>PHP License</license> - <state>alpha</state> - <notes>Promised design change. Image_Tools now implements - the factory pattern I promised on pear-dev.</notes> - </release> - </changelog> + the factory pattern I promised on pear-dev. + </notes> + </release> + <release> + <version>0.3.0</version> + <date>2005-10-02</date> + <license>PHP License</license> + <state>alpha</state> + <notes>Hurried release of Image_Tools in order to introduce new API and features + </notes> + </release> + </changelog> </package> http://cvs.php.net/co.php/pear/Image_Tools/Image/Tools/Marquee.php?r=1.1&p=1 Index: pear/Image_Tools/Image/Tools/Marquee.php +++ pear/Image_Tools/Image/Tools/Marquee.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ // {{{ Header /** * This is a driver file contains the Image_Tools_Marquee class. * * PHP versions 4 and 5 * * LICENSE: * * The PHP License, version 3.0 * * Copyright (c) 1997-2005 The PHP Group * * This source file is subject to version 3.0 of the PHP license, * that is bundled with this package in the file LICENSE, and is * available through the world-wide-web at the following url: * http://www.php.net/license/3_0.txt. * If you did not receive a copy of the PHP license and are unable to * obtain it through the world-wide-web, please send a note to * license@php.net so we can mail you a copy immediately. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version CVS: $Id: Marquee.php,v 1.1 2005/10/02 17:52:59 firman Exp $ */ // }}} // {{{ Dependencies /** * Load Image_Tools as the base class. */ require_once 'Image/Tools.php'; // }}} // {{{ Constants /** * Image_Tools_Marquee rectangle marquee. * * @name IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE * @access public */ define('IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE', 'marquee_rectangle'); /** * Image_Tools_Marquee single column marquee. * * @name IMAGE_TOOLS_MARQUEE_TYPE_SINGLECOL * @access public */ define('IMAGE_TOOLS_MARQUEE_TYPE_SINGLECOL', 'marquee_singlecol'); /** * Image_Tools_Marquee single row marquee. * * @name IMAGE_TOOLS_MARQUEE_TYPE_SINGLEROW * @access public */ 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 * @access public */ define('IMAGE_TOOLS_MARQUEE_TYPE_POLYGON', 'marquee_polygon'); // }}} // {{{ Class: Image_Tools_Marquee /** * This class provide marquee extraction tool for manipulating an image. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version Release: @package_version@ */ class Image_Tools_Marquee extends Image_Tools { // {{{ Properties /** * Marquee options: * <pre> * sample mixed Sample image, a GD image resource or string filename. * x int X position, this sets X position where marquee will be * placed. * y int Y position, this sets Y position where marquee will be * placed. * </pre> * * @var array * @access protected */ var $options = array( 'image' => null, // Destination image. 'sample' => null, // Sample image. 'x' => 0, // X position. 'y' => 0 // Y position. ); /** * Available options for Image_Tools_Marquee. * * @var array * @access protected */ var $availableOptions = array( 'image' => 'mixed', 'sample' => 'mixed', 'x' => 'int', 'y' => 'int' ); /** * Available methods for Image_Tool_Marquee (only public methods). * * @var array * @access protected */ var $availableMethods = array( 'setRectangleMarquee' => array( 'topLeftX' => 'int', 'topLeftY' => 'int', 'bottomRightX' => 'int', 'bottomRightY' => 'int' ), 'setSingleColMarquee' => array( 'x' => 'int' ), 'setSingleRowMarquee' => array( 'y' => 'int' ) ); /** * Image_Tools_Marquee API version. * * @var string * @access protected */ var $version = '0.1'; /** * Marquee information. * * @var array * @access private */ var $_marquee = array(); /** * Sample image. * * @var resource * @access private */ var $_sample = null; // }}} // {{{ _init() /** * Initialize some internal variables. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access private * @see Image_Tools::createImage() */ function _init() { $res = Image_Tools::createImage($this->options['sample']); if (PEAR::isError($res)) { return $res; } $this->_sample = $res; $res = Image_Tools::createImage($this->options['image']); if (PEAR::isError($res)) { return $res; } $this->resultImage = $res; return true; } // }}} // {{{ 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. * @access public * @see Image_Tools_Marquee::_setMarquee() */ function setRectangleMarquee($topLeftX, $topLeftY, $bottomRightX, $bottomRightY) { if ($topLeftX > $bottomRightX) { $tmp = $topLeftX; $topLeftX = $bottomRightX; $bottomRightX = $tmp; } if ($topLeftY > $bottomRightY) { $tmp = $bottomRightY; $topLeftY = $bottomRightY; $bottomRightY = $tmp; } $points = array($topLeftX, $topLeftY, $bottomRightX, $bottomRightY); $this->_setMarquee(IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE, $points); return true; } // }}} // {{{ setSingleColumnMarquee() /** * Set marquee using single column marquee. * * @param int $x X coordinate. * * @return bool Always TRUE. * @access public * @see Image_Tools_Marquee::_setMarquee() */ function setSingleColumnMarquee($x) { $this->_setMarquee(IMAGE_EXTRACT_MARQUEE_TYPE_SINGLECOL, $x); return true; } // }}} // {{{ setSingleRowMarquee() /** * Set marquee using single row marquee. * * @param int $y Y coordinate. * * @return bool Always TRUE. * @access public * @see Image_Tools_Marquee::_setMarquee() */ function setSingleRowMarquee($y) { $this->_setMarquee(IMAGE_EXTRACT_MARQUEE_TYPE_SINGLEROW, $y); return true; } // }}} // {{{ render() /** * Draw extraction result to resource. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access public * @see Image_Tools_Marquee::_extractRectangle(), * Image_Tools_Marquee::_extractSingleCol(), * Image_Tools_Marquee::_extractSingleRow() */ function render() { $res = $this->_init(); if (PEAR::isError($res)) { return $res; } if (!Image_Tools::isGDImageResource($this->resultImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); } $x = $this->options['x']; $y = $this->options['y']; switch ($this->_marquee['type']) { case IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE: $this->_extractRectangle($this->resultImage, $x, $y); break; case IMAGE_TOOLS_MARQUEE_TYPE_SINGLECOL: $this->_extractSingleColumn($this->resultImage, $x, $y); break; case IMAGE_TOOLS_MARQUEE_TYPE_SINGLEROW: $this->_extractSingleRow($this->resultImage, $x, $y); break; } return true; } // }}} // {{{ _setMarquee() /** * Set marquee informations. * * @param string $type Marquee type. Use marquee type defined constants. * @param mixed $points Marquee coordinate points. * * @access private */ function _setMarquee($type, $points) { $this->_marquee = array( 'type' => $type, 'points' => $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. * * @access private */ 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; imagecopymerge($img, $this->_sample, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, 100); } // }}} // {{{ _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. * * @access private */ function _extractSingleColumn(&$img, $dstX, $dstY) { $srcX = $this->_marquee['points']; $srcY = 0; $srcW = 1; $srcH = imagesy($this->_sample); imagecopymerge($img, $this->_sample, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, 100); } // }}} // {{{ _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. * * @access private */ function _extractSingleRow(&$img, $dstX, $dstY) { $srcX = 0; $srcY = $this->_marquee['points']; $srcW = imagesx($this->_sample); $srcH = 1; imagecopymerge($img, $this->_sample, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, 100); } // }}} } // }}} /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/Image/Tools/Mask.php?r=1.1&p=1 Index: pear/Image_Tools/Image/Tools/Mask.php +++ pear/Image_Tools/Image/Tools/Mask.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ // {{{ Header /** * This is a driver file contains the Image_Tools_Mask class. * * PHP versions 4 and 5 * * LICENSE: * * The PHP License, version 3.0 * * Copyright (c) 1997-2005 The PHP Group * * This source file is subject to version 3.0 of the PHP license, * that is bundled with this package in the file LICENSE, and is * available through the world-wide-web at the following url: * http://www.php.net/license/3_0.txt. * If you did not receive a copy of the PHP license and are unable to * obtain it through the world-wide-web, please send a note to * license@php.net so we can mail you a copy immediately. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version CVS: $Id: Mask.php,v 1.1 2005/10/02 17:52:59 firman Exp $ */ // }}} // {{{ Dependencies /** * Load Image_Tools as the base class. */ require_once 'Image/Tools.php'; /** * Require for color mixing. Notes: conflict when integrated with * Image_Color v1.0.0 (http://pear.php.net/package/Image_Color). */ require_once 'Image/Color.php'; // }}} // {{{ Class: Image_Tools_Mask /** * This class provide masking tool for manipulating an image. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version Release: @package_version@ */ class Image_Tools_Mask extends Image_Tools { // {{{ Properties /** * Mask options: * <pre> * 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 * mask * </pre> * * @var array * @access protected */ var $options = array( '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. * * @var array * @access protected */ var $availableOptions = array( 'image' => 'mixed', 'mask' => 'mixed', 'sample' => 'mixed', 'mask_color' => 'mixed', 'unmask_color' => 'mixed', 'antialias' => 'bool', 'antialias_factor' => 'int' ); /** * There is no public methods in Image_Tool_Mask. * * @var array * @access protected */ var $availableMethods = array(); /** * Image_Tools_Mask API version. * * @var string * @access protected */ var $version = '0.1'; /** * GD image resource for mask image. * * @var resource * @access private */ var $_maskImage; /** * GD image resource for sample image. * * @var resource * @access private */ var $_sampleImage; // }}} // {{{ _init() /** * Initialize some internal variables. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access private */ function _init() { $res = Image_Tools::createImage($this->options['mask']); if (PEAR::isError($res)) { return $res; } $this->_maskImage = $res; $res = Image_Tools::createImage($this->options['sample']); if (PEAR::isError($res)) { return $res; } $this->_sampleImage = $res; $res = Image_Tools::createImage($this->options['image']); if (PEAR::isError($res)) { return $res; } $this->resultImage = $res; return true; } // }}} // {{{ render() /** * Apply tools to image. * * 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_Error TRUE on success or PEAR_Error on failure. * @access private * @see Image_Tools_Mask::_getNearestColors() */ function render() { $res = $this->_init(); if (PEAR::isError($res)) { return $res; } if (!Image_Tools::isGDImageResource($this->_maskImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_maskImage'); } if (!Image_Tools::isGDImageResource($this->_sampleImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_sampleImage'); } if (!Image_Tools::isGDImageResource($this->resultImage)) { 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); if ($this->options['antialias']) { $closesColors = $this->_getNearestColors(); } else { $closesColors = array($this->options['maskColor']); } imagealphablending($this->resultImage, true); // 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) { continue; } // grab color at x, y and convert to hex color format $index = imagecolorat($this->_maskImage, $x, $y); $maskRGBA = imagecolorsforindex($this->_maskImage, $index); $maskColor = Image_Color::rgb2hex(array_values($maskRGBA)); // check color in closes colors collection if (in_array($maskColor, $closesColors)) { // grab color at x, y from sample image $index = imagecolorat($this->_sampleImage, $x, $y); $sampleRGBA = imagecolorsforindex($this->_sampleImage, $index); // allocate color on destination image $color = imagecolorresolvealpha($this->resultImage, $sampleRGBA['red'], $sampleRGBA['green'], $sampleRGBA['blue'], $sampleRGBA['alpha']); // set a pixel color at destination image imagesetpixel($this->resultImage, $x, $y, $color); } } } return true; } // }}} // {{{ _getNearestColors /** * Get nearest colors between mask color and unmask color using * antialias factor. * * @return array Colors range. * @access private */ function _getNearestColors() { $objColor = new Image_Color; $objColor->setColors($this->options['mask_color'], $this->options['unmask_color']); return $objColor->getRange($this->options['antialias_factor']); } // }}} } // }}} /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/Image/Tools/Swap.php?r=1.1&p=1 Index: pear/Image_Tools/Image/Tools/Swap.php +++ pear/Image_Tools/Image/Tools/Swap.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ // {{{ Header /** * This is a driver file contains the Image_Tools_Swap class. * * PHP versions 4 and 5 * * LICENSE: * * The PHP License, version 3.0 * * Copyright (c) 1997-2005 The PHP Group * * This source file is subject to version 3.0 of the PHP license, * that is bundled with this package in the file LICENSE, and is * available through the world-wide-web at the following url: * http://www.php.net/license/3_0.txt. * If you did not receive a copy of the PHP license and are unable to * obtain it through the world-wide-web, please send a note to * license@php.net so we can mail you a copy immediately. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version CVS: $Id: Swap.php,v 1.1 2005/10/02 17:52:59 firman Exp $ */ // }}} // {{{ Dependencies /** * 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. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version Release: @package_version@ */ class Image_Tools_Swap extends Image_Tools { // {{{ Properties /** * Swap options: * <pre> * 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) * </pre> * * @var array * @access protected */ var $options = array( 'image' => null, 'format' => 'RBG' ); /** * Available options for Image_Tools_Swap. * * @var array * @access protected */ var $availableOptions = array( 'image' => 'mixed', 'format' => 'string' ); /** * Available methods for Image_Tool_Swap (only public methods). * * @var array * @access protected */ var $availableMethods = array( 'swapColor' => array( 'format' => 'string', 'rgb' => 'array' ) ); /** * Image_Tools_Swap API version. * * @var string * @access protected */ var $version = '0.1'; // }}} // {{{ _init() /** * Initialize some internal variables. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access private * @see Image_Tools::createImage() */ function _init() { $res = Image_Tools::createImage($this->options['image']); if (PEAR::isError($res)) { return $res; } $this->resultImage = $res; return true; } // }}} // {{{ render() /** * Apply swap color to image and output result. * * This function swap channel color 'R', 'G', 'B' to set format. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access protected */ function render() { $res = $this->_init(); if (PEAR::isError($res)) { return $res; } if (!Image_Tools::isGDImageResource($this->resultImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); } if (!preg_match('@RBG|BGR|BRG|GRB|GBR$@i', $this->options['format'])) { return PEAR::raiseError('Invalid swap format'); } $width = imagesx($this->resultImage); $height = imagesy($this->resultImage); $destImg = imagecreatetruecolor($width, $height); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $index = imagecolorat($this->resultImage, $x, $y); $rgb = imagecolorsforindex($this->resultImage, $index); $rgb = Image_Tools_Swap::swapColor($this->options['format'], $rgb); $color = imagecolorallocate($destImg, $rgb['r'], $rgb['g'], $rgb['b']); imagesetpixel($destImg, $x, $y, $color); } } $this->resultImage = $destImg; return true; } // }}} // {{{ swapColor() /** * 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 * - r, g and b, or * - 0, 1 and 2 * * @return array|PEAR_Error Swapped color channel, an array contains * keys r, g and b on success or PEAR_Error * on failure. * @access public */ function swapColor($format, $rgb) { if (!is_array($rgb)) { return PEAR::raiseError('Type mismatch for argument 2'); } $format = str_split(strtolower($format)); 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'])) { $color = $rgb; } elseif (isset($rgb[0]) && isset($rgb[1]) && isset($rgb[2])) { $color['r'] = $rgb[0]; $color['g'] = $rgb[1]; $color['b'] = $rgb[2]; } else { return PEAR::raiseError('Invalid RGB color'); } return array( $format[0] => $color['r'], $format[1] => $color['g'], $format[2] => $color['b'] ); } // }}} } // }}} /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/package2.xml?r=1.1&p=1 Index: pear/Image_Tools/package2.xml +++ pear/Image_Tools/package2.xml <?xml version="1.0" encoding="UTF-8"?> <package packagerversion="1.4.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>Image_Tools</name> <channel>pear.php.net</channel> <summary>Tools collection for images</summary> <description>Tools collection of common image manipulations. </description> <lead> <name>Tobias</name> <user>toby</user> <email>toby@php.net</email> <active>yes</active> </lead> <lead> <name>Firman Wandayandi</name> <user>firman</user> <email>firman@php.net</email> <active>yes</active> </lead> <developer> <name>Stefan Neufeind</name> <user>neufeind</user> <email>pear.neufeind@speedpartner.de</email> <active>yes</active> </developer> <date>2005-10-02</date> <time>23:36:21</time> <version> <release>0.3.0</release> <api>0.3.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.php.net/license">PHP License</license> <notes>Hurried release of Image_Tools in order to introduce new API and features </notes> <contents> <dir name="/"> <dir name="docs"> <dir name="examples"> <dir name="images"> <file baseinstalldir="" name="mask.png" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="master.PNG" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="pear.PNG" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> <!-- /docs/examples/images --> <file baseinstalldir="" name="border.php" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="marquee.php" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="mask.php" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="swap.php" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> <!-- /docs/examples --> </dir> <!-- /docs --> <dir name="Image"> <dir name="Tools"> <file baseinstalldir="" name="Border.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="Marquee.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="Mask.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="Swap.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> <!-- /Image/Tools --> <file baseinstalldir="" name="Tools.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> <!-- /Image --> </dir> <!-- / --> </contents> <dependencies> <required> <php> <min>4.3.0</min> </php> <pearinstaller> <min>1.4.0b1</min> </pearinstaller> <package> <name>PEAR</name> <channel>pear.php.net</channel> <min>1.3.3</min> </package> <package> <name>Image_Color</name> <channel>pear.php.net</channel> <min>1.0.1</min> </package> <package> <name>PHP_Compat</name> <channel>pear.php.net</channel> <min>1.4.1</min> </package> <extension> <name>gd</name> </extension> </required> </dependencies> <phprelease /> <changelog> <release> <version> <release>0.1</release> <api>0.1</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2003-11-04</date> <license uri="http://www.php.net/license">PHP License</license> <notes>3rd try for initial release. All releases before were broken, so I decided to delete all of them and start new with 0.1 </notes> </release> <release> <version> <release>0.2</release> <api>0.2</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2003-11-13</date> <license uri="http://www.php.net/license">PHP License</license> <notes>Promised design change. Image_Tools now implements the factory pattern I promised on pear-dev. </notes> </release> <release> <version> <release>0.3.0</release> <api>0.3.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2005-10-02</date> <license uri="http://www.php.net/license">PHP License</license> <notes>Hurried release of Image_Tools in order to introduce new API and features </notes> </release> </changelog> </package> http://cvs.php.net/co.php/pear/Image_Tools/docs/examples/border.php?r=1.1&p=1 Index: pear/Image_Tools/docs/examples/border.php +++ pear/Image_Tools/docs/examples/border.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */ // CVS: $Id: border.php,v 1.1 2005/10/02 17:53:00 firman Exp $ /** * Load Image_Tools border tool */ require_once 'Image/Tools.php'; $options = array( 'image' => 'images/pear.png', ); // Create new Image_Tools_Border object instance $toolBorder =& Image_Tools::factory('border', $options); if (PEAR::isError($toolBorder)) { die($toolBorder->toString()); } // Create rounded border. $toolBorder->rounded(); // Also try bevel border. #$toolBorder->bevel(); // Apply border to the image and send it to browser $err = $toolBorder->display(); if (PEAR::isError($err)) { die($err->toString()); } /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/docs/examples/marquee.php?r=1.1&p=1 Index: pear/Image_Tools/docs/examples/marquee.php +++ pear/Image_Tools/docs/examples/marquee.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */ // CVS: $Id: marquee.php,v 1.1 2005/10/02 17:53:00 firman Exp $ /** * Load Image_Tools marquee tool */ require_once 'Image/Tools.php'; // Create destination image when masked sample image will be draw. $filename = 'images/master.png'; $destImage = imagecreatefrompng($filename); // Sets sample image, x position and y position. $options = array( 'image' => $destImage, 'sample' => 'images/pear.png', 'x' => 10, 'y' => 10 ); // Create new Image_Tools_Marquee object instance $toolMarquee =& Image_Tools::factory('marquee', $options); if (PEAR::isError($toolMarquee)) { die($toolMarquee->toString()); } // Sets rectangle marquee $toolMarquee->setRectangleMarquee(10, 10, 40, 40); // Apply marquee to the image and send it to browser $err = $toolMarquee->display(); if (PEAR::isError($err)) { die($err->toString()); } /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/docs/examples/mask.php?r=1.1&p=1 Index: pear/Image_Tools/docs/examples/mask.php +++ pear/Image_Tools/docs/examples/mask.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */ // CVS: $Id: mask.php,v 1.1 2005/10/02 17:53:00 firman Exp $ /** * Load Image_Tools. */ require_once 'Image/Tools.php'; // Sets mask and sample image. $options = array( 'image' => 'images/master.png', 'mask' => 'images/mask.png', 'sample' => 'images/pear.png' ); // Create new instance of Image_Mask $toolMask =& Image_Tools::factory('mask', $options); if (PEAR::isError($toolMask)) { die($toolMask->toString()); } // Apply mask and send the result image to browser $err = $toolMask->display(); if (PEAR::isError($err)) { die($err->toString()); } /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/docs/examples/swap.php?r=1.1&p=1 Index: pear/Image_Tools/docs/examples/swap.php +++ pear/Image_Tools/docs/examples/swap.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */ // CVS: $Id: swap.php,v 1.1 2005/10/02 17:53:00 firman Exp $ /** * Require the swap tool */ require_once 'Image/Tools.php'; $options = array( 'image' => 'images/pear.png' ); // Create new Image_Tools_Swap object instance $tool =& Image_Tools::factory('swap', $options); if (PEAR::isError($tool)) { die($tool->toString()); } // Swap the image channel colors and send the result image to browser $err = $tool->display(); if (PEAR::isError($err)) { die($err->toString()); } /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/docs/readme.txt?r=1.1&p=1 Index: pear/Image_Tools/docs/readme.txt +++ pear/Image_Tools/docs/readme.txt For actual documentation, please have a look at: http://www.schlitt.info/index.php/content.projects_image_tools
http://cvs.php.net/diff.php/pear/Image_Tools/Image/Tools.php?r1=1.3&r2=1.4&ty=u Index: pear/Image_Tools/Image/Tools.php diff -u pear/Image_Tools/Image/Tools.php:1.3 pear/Image_Tools/Image/Tools.php:1.4 --- pear/Image_Tools/Image/Tools.php:1.3 Wed Feb 23 07:16:08 2005 +++ pear/Image_Tools/Image/Tools.php Sun Oct 2 13:52:56 2005 @@ -1,45 +1,63 @@ <?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +// {{{ Header /** - * Image_Tools. - * - * This is the main file of the Image_Tools package. This file has to be - * included for usage of Image_Tools. + * This is a main file of Image_Tools package. * * PHP versions 4 and 5 * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. - * - * @category Image - * @package Tools - * @author Tobias Schlitt <toby@php.net> - * @copyright 1997-2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Tools.php,v 1.3 2005/02/23 12:16:08 toby Exp $ - * @link http://pear.php.net/package/Net_FTP2 - * @since File available since Release 0.0.1 + * LICENSE: + * + * The PHP License, version 3.0 + * + * Copyright (c) 1997-2005 The PHP Group + * + * This source file is subject to version 3.0 of the PHP license, + * that is bundled with this package in the file LICENSE, and is + * available through the world-wide-web at the following url: + * http://www.php.net/license/3_0.txt. + * If you did not receive a copy of the PHP license and are unable to + * obtain it through the world-wide-web, please send a note to + * license@php.net so we can mail you a copy immediately. + * + * @category Images + * @package Image_Tools + * @author Tobias Schlitt <toby@php.net> + * @author Firman Wandayandi <firman@php.net> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt + * The PHP License, version 3.0 + * @version CVS: $Id: Tools.php,v 1.4 2005/10/02 17:52:56 firman Exp $ */ - + +// }}} +// {{{ Dependencies /** - * Require PEAR file for error handling. + * load PEAR for error handling. */ require_once 'PEAR.php'; /** - * Require PHP_Compat for PHP5 compatibility (is_a()) + * load PHP_Compat for PHP backward compatibility. */ require_once 'PHP/Compat.php'; +/** + * is_a(), since PHP 4.2.0 + */ @PHP_Compat::loadFunction('is_a'); + +/** + * image_type_to_mime_type, since PHP 4.3.0 + */ @PHP_Compat::loadFunction('image_type_to_mime_type'); +// }}} +// {{{ Constants + /** * Image_Tools error, indicating that the given tool was not found. * @@ -69,7 +87,7 @@ /** * Image_Tools error, indicating that the given option was of a wrong type. * - * @name IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE + * @name IMAGE_TOOLS_BASE_ERR_OPTION_INVALID * @access public */ define('IMAGE_TOOLS_BASE_ERR_OPTION_INVALID', -4); @@ -140,7 +158,7 @@ define('IMAGE_TOOLS_BASE_ERR_NONSTATIC_FAILED', -11); /** - * Image_Tools error, indicating that you called a static method + * Image_Tools error, indicating that you called a static method * statically, which may only be called non statically. * * @name IMAGE_TOOLS_BASE_ERR_STATIC_FAILED @@ -148,24 +166,27 @@ */ define('IMAGE_TOOLS_BASE_ERR_STATIC_FAILED', -12); +// }}} +// {{{ Class: Image_Tools + /** * This is the Image_Tools base class * Every image-tool has to derive from this class and implement several methods * itself. Other methods are implemented in the base class directly, but may - * only be called on the sub-classes. The only method being called directly from the - * base class is the factory() method. + * only be called on the sub-classes. The only method being called directly from + * the base class is the factory() method. * - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @category Image - * @package Tools - * @author Tobias Schlitt <toby@php.net> - * @copyright 1997-2005 The PHP Group - * @version Release: @package_version@ - * @link http://pear.php.net/package/Net_FTP - * @since 0.0.1 - * @access public + * @category Images + * @package Image_Tools + * @author Tobias Schlitt <toby@php.net> + * @author Firman Wandayandi <firman@php.net> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt + * The PHP License, version 3.0 + * @version Release: @package_version@ */ class Image_Tools { + // {{{ Properties /** * Contain the options inside all subclasses. @@ -232,7 +253,18 @@ * @access protected */ var $apiVersion = '0.1'; - + + /** + * Result rendered image. + * + * @var resource + * @access protected + */ + var $resultImage = null; + + // }}} + // {{{ Constructor + /** * Constructor * @@ -245,12 +277,20 @@ * @see IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FORBIDEN */ function Image_Tools($options = array()) - { + { + PEAR::setErrorHandling(PEAR_ERROR_TRIGGER); if (is_a($this, 'Image_Tools') && !is_subclass_of($this, 'Image_Tools')) { - $this =& PEAR::raiseError('Cannot instanciate Image_Tools directly', IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FORBIDEN); + PEAR::raiseError('Cannot instanciate Image_Tools directly', + IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FORBIDEN); } + + $this->set($options); + PEAR::setErrorHandling(PEAR_ERROR_RETURN); } + // }}} + // {{{ factory() + /** * Create a new instance of an image tool * @@ -264,41 +304,55 @@ * @return object New image tool on success or PEAR_Error on failure * @access public * @static - * @see IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED, IMAGE_TOOLS_BASE_ERR_CLASS_INVALID, IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED + * @see IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED, + * IMAGE_TOOLS_BASE_ERR_CLASS_INVALID, + * IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, + * IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED */ function &factory($tool, $options = array()) { if (isset($this)) { - return PEAR::raiseError('This method may only be called statically', IMAGE_TOOLS_BASE_ERR_NONSTATIC_FAILED); + return PEAR::raiseError('This method may only be called statically', + IMAGE_TOOLS_BASE_ERR_NONSTATIC_FAILED); } + // Renice the tool name $toolParts = @explode('_', $tool); if (empty($toolParts) || !is_array($toolParts)) { $toolParts[] = $tool; } - array_walk($toolParts, ucfirst); + + foreach ($toolParts as $key => $value) { + $toolParts[$key] = ucfirst($value); + } $tool = implode('_', $toolParts); $toolPath = 'Image/Tools/'.$tool.'.php'; - + // Include the tool class - @require($toolPath); - - $className = "Image_Tools_${tool}.php"; + require_once($toolPath); + + $className = "Image_Tools_${tool}"; if (!class_exists($className)) { - return PEAR::raiseError('File not found '.$toolPath.' or undifined class '.$className, IMAGE_TOOLS_BASE_ERR_CLASS_INVALID); + return PEAR::raiseError('File not found ' . $toolPath . + ' or undefined class '.$className, + IMAGE_TOOLS_BASE_ERR_CLASS_INVALID); } - @$obj =& new $classname($options); + @$obj =& new $className($options); if (!is_object($obj) || !is_a($obj, $className)) { - return PEAR::raiseError('Could not instanciate image tool '.$className, IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED); + return PEAR::raiseError('Could not instanciate image tool '.$className, + IMAGE_TOOLS_BASE_ERR_INSTANCIATION_FAILED); } - $res = $obj->setOption($options); + $res = $obj->set($options); if (PEAR::isError($res)) { return $res; } return $obj; } + // }}} + // {{{ set() + /** * Set the option(s) * Set a single or multiple options. The parameter of that method may @@ -311,16 +365,18 @@ * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure * @access protected - * @see IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED + * @see IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, + * IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED */ function set($option, $value = null) { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } if (is_array($option)) { foreach ($option as $key => $value) { - $res = $this->setOption($key, @$value); + $res = $this->set($key, @$value); if (PEAR::isError($res)) { return $res; } @@ -334,7 +390,10 @@ $this->options[$option] = $value; return true; } - + + // }}} + // {{{ isValidOption() + /** * Has the option a valid value? * Determines, if the value given is valid for the option. @@ -344,7 +403,8 @@ * * @return bool|PEAR_Error TRUE on acceptans or PEAR_Error on failure * @access protected - * @see IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED + * @see IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE, + * IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED */ function isValidOption($name, $value) @@ -355,7 +415,7 @@ } $type = $this->availableOptions[$name]; switch ($type) { - case 'mixed': + case 'mixed': return true; break; case 'bool': @@ -382,24 +442,34 @@ } break; } - return PEAR::raiseError('Wrong type for option '.$name.'. Requires '.$type.', but is '.gettype($value), IMAGE_TOOLS_BASE_ERR_WRONGOPTIONTYPE); + return PEAR::raiseError('Wrong type for option ' . $name . + '. Requires '. $type .', but is ' . gettype($value), + IMAGE_TOOLS_BASE_ERR_OPTION_INVALID); } - + + // }}} + // {{{ get() + /** * Get the value of the option * - * returns the value of an option of, an error if the option is not available. + * returns the value of an option of, an error if the option is not + * available. * * @param string $option Option name. * - * @return mixed|PEAR_Error Option value on success or PEAR_Error on failure. + * @return mixed|PEAR_Error Option value on success or + * PEAR_Error on failure. * @access public - * @see IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED, IMAGE_TOOLS_BASE_ERR_OPTION_NOTSET, IMAGE_TOOLS_BASE_ERR_STATIC_FAILED + * @see IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED, + * IMAGE_TOOLS_BASE_ERR_OPTION_NOTSET, + * IMAGE_TOOLS_BASE_ERR_STATIC_FAILED */ function get($option) { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } $res = $this->supportsOption($option); if (PEAR::isError($res)) { @@ -408,9 +478,128 @@ if (isset($this->options[$option])) { return $this->options[$option]; } - return PEAR::raiseError('Option '.$option.' not set', IMAGE_TOOLS_BASE_ERR_OPTION_NOTSET); + return PEAR::raiseError('Option '.$option.' not set', + IMAGE_TOOLS_BASE_ERR_OPTION_NOTSET); + } + + // }}} + // {{{ createImageFromFile() + + /** + * Create a GD image resource from file (JPEG, PNG, WBMP and XBM support). + * + * @param string $filename The image filename. + * + * @return mixed GD image resource on success, PEAR_Error on failure. + * @access public + * @static + */ + function createImageFromFile($filename) + { + if (!is_file($filename) || !is_readable($filename)) { + return PEAR::raiseError('Unable to open file "' . $filename . '"'); + } + + // determine image format + list( , , $imgType) = getimagesize($filename); + + switch ($imgType) { + case IMAGETYPE_JPEG: + return imagecreatefromjpeg($filename); + break; + case IMAGETYPE_PNG: + return imagecreatefrompng($filename); + break; + case IMAGETYPE_WBMP: + return imagecreatefromwbmp($filename); + break; + case IMAGETYPE_XBM: + return imagecreatefromxbm($filename); + break; + default: + return PEAR::raiseError('Unsupport image type'); + } + } + + // }}} + // {{{ createImageFromString() + + /** + * Create a GD image resource from a string data. + * + * @param string $data The string image data. + * + * @return mixed GD image resource on success, PEAR_Error on failure. + * @access public + * @static + */ + function createImageFromString($data) + { + if (!is_string($data) || empty($data)) { + PEAR::raiseError('Invalid data value.'); + } + + $img = imagecreatefromstring($data); + if ($img === false) { + return PEAR::raiseError('Failed to create image from string data'); + } + return $img; + } + + // }}} + // {{{ createImage() + + /** + * Create a GD image resource from given input. + * + * This method tried to detect what the input, if it is a file the + * createImageFromFile will be called, otherwise createImageFromString(). + * + * @param mixed $input The input for creating an image resource. The value + * may a string of filename, string of image data or + * GD image resource. + * + * @return resource|PEAR_Error An GD image resource on success or + * PEAR_Error on failure. + * @access public + * @see createImageFromFile() + * @see createImageFromString() + */ + function createImage($input) + { + if (is_file($input)) { + return Image_Tools::createImageFromFile($input); + } else if (is_string($input)) { + return Image_Tools::createImageFromString($input); + } else if (Image_Tools::isGDImageResource($input)) { + return $input; + } + return PEAR::raiseError('Invalid input given.'); } + // }}} + // {{{ isGDImageResource() + + /** + * Find the whether a value is the GD image resource or not. + * + * @param mixed $value Value to evaluate. + * + * @return bool TRUE if a value is the GD image resource, otherwise FALSE. + * @access public + * @static + */ + function isGDImageResource($value) + { + if (is_resource($value) && get_resource_type($value) == 'gd') { + return true; + } + return false; + } + + // }}} + // {{{ render() + /** * Render the result of a tool to the given image * @@ -419,92 +608,129 @@ * method gets a GD2 image as it's parameter. The creation of images inside * Image_Tools is not supported. * - * @param resource $img GD image resource * @access protected * @see IMAGE_TOOLS_BASE_ERR_STATIC_FAILED */ - function render (&$img) + function render() { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } } + // }}} + // {{{ getResultImage() + + /** + * Get rendered image. + * + * @return resource The GD image resource of rendered result. + * @access public + */ + function getResultImage() + { + return $this->resultImage; + } + + // }}} + // {{{ display() + /** * Display rendered image (send it to browser). * This method is a common implementation to render and output an image. * The method calls the render() method automatically and outputs the * image to the browser. * - * @param resource $image GD image resource. - * @param int $type optional Type of format image (use defined image type constants), - * default is IMAGETYPE_PNG. + * @param int $type optional Type of format image (use defined image + * type constants), default is IMAGETYPE_PNG. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. - * @access protected - * @see IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED, IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED + * @access public + * @see IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED, + * IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED */ - function display(&$image, $type = IMAGETYPE_PNG) + function display($type = IMAGETYPE_PNG) { + $res = $this->render(); + if (PEAR::isError($res)) { + return PEAR::raiseError('Error rendering: ' . $resultImage->getMessage()); + } + $ctype = image_type_to_mime_type($type); if (!headers_sent()) { header('Content-Type: ' . $ctype); } else { - PEAR::raiseError('Headers have already been sent. Could not display image.', IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED); + return PEAR::raiseError('Headers have already been sent. Could not display image.', + IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED); } switch ($type) { case IMAGETYPE_PNG: - imagepng($this->render($image)); + imagepng($this->resultImage); break; case IMAGETYPE_JPEG: - imagejpeg($this->render($image)); + imagejpeg($this->resultImage); break; case IMAGETYPE_WBMP: - imagewbmp($this->render($image)); + imagewbmp($this->resultImage); break; default: - return PEAR::raiseError('Image type '.$ctype.' not supported by PHP', IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED); + return PEAR::raiseError('Image type '.$ctype.' not supported by PHP', + IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED); break; } return true; } + // }}} + // {{{ save() + /** * Save rendered image to a file. * - * @param resource $image GD image resource. * @param string $path Path to destination filename. - * @param int $type optional Type of image format (use defined image type constants), - * default is IMAGETYPE_PNG. + * @param int $type optional Type of image format (use defined image type + * constants), default is IMAGETYPE_PNG. * * @return bool|PEAR_Error TRUE on success, PEAR_Error on failure. - * @access protected - * @see IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED, IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED + * @access public + * @see IMAGE_TOOLS_BASE_ERR_HEADERSEND_FAILED, + IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED */ - function save(&$image, $path, $type = IMAGETYPE_PNG) + function save($path, $type = IMAGETYPE_PNG) { + $res = $this->render(); + if (PEAR::isError($res)) { + return PEAR::raiseError('Error rendering: ' . $resultImage->getMessage()); + } + switch ($type) { case IMAGETYPE_PNG: - $res = imagepng($this->render($image), $path); + $res = imagepng($this->resultImage, $path); break; case IMAGETYPE_JPEG: - $res = imagejpeg($this->render($image), $path); + $res = imagejpeg($this->resultImage, $path); break; case IMAGETYPE_WBMP: - $res = imagewbmp($this->render($image), $path); + $res = imagewbmp($this->resultImage, $path); break; default: - return PEAR::raiseError('Image type '.$ctype.' not supported by PHP', IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED); + return PEAR::raiseError('Image type '.$ctype.' not supported by PHP', + IMAGE_TOOLS_BASE_ERR_IMAGETYPE_UNSUPPORTED); break; } if (!$res) { - PEAR::raiseError('Saving image '.$path.' failed', IMAGE_TOOLS_BASE_ERR_SAVEIMAGE_FAILED); + PEAR::raiseError('Saving image '.$path.' failed', + IMAGE_TOOLS_BASE_ERR_SAVEIMAGE_FAILED); } return true; } + // }}} + // {{{ supportsOption() + /** * Find out the whether a subclass supports the option * @@ -512,19 +738,25 @@ * * @return bool TRUE if supported, otherwise FALSE * @access protected - * @see IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED, IMAGE_TOOLS_BASE_ERR_STATIC_FAILED + * @see IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED, + * IMAGE_TOOLS_BASE_ERR_STATIC_FAILED */ function supportsOption($option) { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } - if (in_array($option, $this->availableOptions)) { + if (isset($this->availableOptions[$option])) { return true; } - return PEAR::raiseError('Unsupported option '.$option, IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED); + return PEAR::raiseError('Unsupported option '.$option, + IMAGE_TOOLS_BASE_ERR_OPTION_UNSUPPORTED); } + // }}} + // {{{ availableOptions() + /** * Get all available options of the subclass * @@ -535,11 +767,15 @@ function availableOptions() { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } return $this->availableOptions; } + // }}} + // {{{ supportsMethod() + /** * Get the method parameters * @@ -553,14 +789,19 @@ function supportsMethod($methodName) { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } if (isset($this->availableMethods[$methodName])) { return $this->availableMethods[$methodName]; } - return PEAR::raiseError('Unsupported method '.$methodName, IMAGE_TOOLS_BASE_ERR_METHOD_UNSUPPORTED); + return PEAR::raiseError('Unsupported method '.$methodName, + IMAGE_TOOLS_BASE_ERR_METHOD_UNSUPPORTED); } + // }}} + // {{{ availableMethods() + /** * Get available methods * @@ -575,11 +816,15 @@ function availableMethods() { if (!isset($this)) { - return PEAR::raiseError('This method may only be called non statically', IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); + return PEAR::raiseError('This method may only be called non statically', + IMAGE_TOOLS_BASE_ERR_STATIC_FAILED); } return $this->availableMethods; } + // }}} + // {{{ getAPIVersion() + /** * Get the API version of the common base * @@ -600,6 +845,9 @@ } } + // }}} + // {{{ getVersion() + /** * Get the subclass version. * @@ -608,7 +856,20 @@ */ function getVersion() { - return $this->version; + return $this->version; } + + // }}} } -?> + +// }}} + +/* + * Local variables: + * mode: php + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> \ No newline at end of file http://cvs.php.net/diff.php/pear/Image_Tools/Image/Tools/Border.php?r1=1.3&r2=1.4&ty=u Index: pear/Image_Tools/Image/Tools/Border.php diff -u pear/Image_Tools/Image/Tools/Border.php:1.3 pear/Image_Tools/Image/Tools/Border.php:1.4 --- pear/Image_Tools/Image/Tools/Border.php:1.3 Wed Feb 23 07:16:09 2005 +++ pear/Image_Tools/Image/Tools/Border.php Sun Oct 2 13:52:59 2005 @@ -1,158 +1,285 @@ <?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +// {{{ Header /** - * Image_Tools_Border. - * - * This file holds the implementation of the image tool Border. The file - * is included using the Image_Tools::factory() method. + * This is a driver file contains the Image_Tools_Border class. * * PHP versions 4 and 5 * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. - * - * @category Image - * @package Tools - * @author Tobias Schlitt <toby@php.net> - * @copyright 1997-2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Border.php,v 1.3 2005/02/23 12:16:09 toby Exp $ - * @link http://pear.php.net/package/Net_FTP2 - * @since File available since Release 0.0.1 + * LICENSE: + * + * The PHP License, version 3.0 + * + * Copyright (c) 1997-2005 The PHP Group + * + * This source file is subject to version 3.0 of the PHP license, + * that is bundled with this package in the file LICENSE, and is + * available through the world-wide-web at the following url: + * http://www.php.net/license/3_0.txt. + * If you did not receive a copy of the PHP license and are unable to + * obtain it through the world-wide-web, please send a note to + * license@php.net so we can mail you a copy immediately. + * + * @category Images + * @package Image_Tools + * @author Firman Wandayandi <firman@php.net> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt + * The PHP License, version 3.0 + * @version CVS: $Id: Border.php,v 1.4 2005/10/02 17:52:59 firman Exp $ */ +// }}} +// {{{ Dependencies + /** - * Require the base class. + * Load Image_Tools as the base class. */ require_once 'Image/Tools.php'; /** - * Image_Tools_Border. - * - * This image tool creates rectengular borders in images. + * Load Image_Color for color handling. + */ +require_once 'Image/Color.php'; + +// }}} +// {{{ Class: Image_Tools_Border + +/** + * This class provide border creation on an image. * - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @category Image - * @package Tools - * @author Tobias Schlitt <toby@php.net> - * @copyright 1997-2005 The PHP Group - * @version Release: @package_version@ - * @link http://pear.php.net/package/Net_FTP - * @since 0.0.1 - * @access public + * @category Images + * @package Image_Tools + * @author Firman Wandayandi <firman@php.net> + * @copyright Copyright (c) 2004-2005 Firman Wandayandi + * @license http://www.php.net/license/3_0.txt + * The PHP License, version 3.0 + * @version Release: @package_version@ */ -class Image_Tools_Border extends Image_Tools { +class Image_Tools_Border extends Image_Tools +{ + // {{{ Properties + + /** + * Border options: + * <pre> + * image mixed Destination image, a filename or an image string + * data or a GD image resource. + * </pre> + * + * @var array + * @access protected + */ + var $options = array( + 'image' => null // An image. + ); + + /** + * Available options for Image_Tools_Border. + * + * @var array + * @access protected + */ + var $availableOptions = array( + 'image' => 'mixed' + ); + + /** + * Available methods for Image_Tool_Border (only public methods). + * + * @var array + * @access protected + */ + var $availableMethods = array( + 'rounded' => array( + 'radius' => 'integer', + 'background' => 'mixed', + 'antiAlias' => 'integer' + ), + 'bevel' => array( + 'size' => 'integer', + 'highlight' => 'mixed', + 'shadow' => 'mixed' + ) + ); + + /** + * Image_Tools_Border API version. + * + * @var string + * @access protected + */ + var $version = '0.1'; + + /** + * Image width. + * + * @var int + * @access private + */ + var $_iWidth = 0; + + /** + * Image height. + * + * @var int + * @access private + */ + var $_iHeight = 0; + + // }}} + // {{{ _init() + /** + * Initialize some internal variables. + * + * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. + * @access private + */ + function _init() + { + $res = Image_Tools::createImage($this->options['image']); + if (PEAR::isError($res)) { + return $res; + } + + $this->resultImage = $res; + $this->_iWidth = imagesx($this->resultImage); + $this->_iHeight = imagesy($this->resultImage); + + return true; + } + + // }}} + // {{{ rounded() /** - * Configuration options - * - * @var array - */ - var $options = array ( 'x' => false, - 'y' => false, - 'width' => false, - 'height' => false, - 'fgColor' => false, - 'bgColor' => false, - 'lineWidth' => 1, - 'roundWidth' => 0); - - /** - * Constructor - * The constructor is normaly called in the factory method of the - * inherited class @see Image_Tools, where you can provide the options - * array, as follows: - * - * <pre> - * array( - * 'x' => top left corner x coordinate - * 'y' => top left corner y coordinate - * 'width' => width of the border - * 'height' => height of the border - * 'fgColor' => color of the border - * 'bgColor' => color of the background - * 'lineWidth' => thickness of the border, default is 1 - * 'roundWidth' => width of the edge rounding, default is no round - * ) - * </pre> - * - * @access public - * @param array $options Options as described above. - */ - function Image_Tools_Border ( $options = array() ) { - foreach ( $options as $option => $value) { - if (isset($this->options[$option])) { - $this->options[$option] = $value; + * Make an image be a rounded edge. + * + * @param int $radius optional Radius size. + * @param mixed $background Background color. + * @param int $antiAlias Anti-alias factor. + * + * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. + * @access public + */ + function rounded($radius = 3, $background = 'FFFFFF', $antiAlias = 3) + { + $res = $this->_init(); + if (PEAR::isError($res)) { + return $res; + } + + if (!Image_Tools::isGDImageResource($this->resultImage)) { + return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); + } + + $background = Image_Color::hex2rgb($background); + $antiAlias = min(3, $antiAlias); + + $iDot = imagecreate(1, 1); + imagecolorallocate($iDot, $background[0], $background[1], $background[2]); + + for ($i = 0 - $radius; $i <= $radius; $i++) { + $y = $i < 0 ? $i + $radius - 1 : $this->_iHeight - ($radius - $i); + for ($j = 0 - $radius; $j <= $radius; $j++) { + $x = $j < 0 ? $j + $radius - 1 : $this->_iWidth - ($radius - $j); + if ($i != 0 || $j != 0) { + $distance = round(sqrt(($i * $i) + ($j * $j))); + $opacity = $distance < $radius - $antiAlias ? + 0 : max(0, 100 - (($radius - $distance) * 33)); + $opacity = $distance > $radius ? 100 : $opacity; + imagecopymerge($this->resultImage, $iDot, $x, $y, 0, 0, 1, 1, $opacity); + } } } + + imagedestroy($iDot); + + return true; } + // }}} + // {{{ bevel() + /** - * Draw the border to the image - * This draws the configured border to the provided image. Beware, that - * every pixel inside the border clipping will be overwritten with the - * given background color. This will be changed in the next release. - * - * @access public - * @return void - */ - function draw ( ) { - $o = $this->options; - - $fgCol = imagecolorallocate($this->img, $o['fgColor']['r'], $o['fgColor']['g'], $o['fgColor']['b']); - $bgCol = imagecolorallocate($this->img, $o['bgColor']['r'], $o['bgColor']['g'], $o['bgColor']['b']); - - // FG - $startXfg = $o['x'] - $o['lineWidth']; - $startYfg = $o['y'] - $o['lineWidth']; - $endXfg = $o['x'] + $o['width'] + $o['lineWidth']; - $endYfg = $o['y'] + $o['height'] + $o['lineWidth']; - - $res = imagefilledrectangle($this->img, $startXfg, $startYfg, $endXfg, $endYfg, $fgCol); - - // BG: - $startXbg = $o['x']; - $startYbg = $o['y']; - $endXbg = $o['x'] + $o['width']; - $endYbg = $o['y'] + $o['height']; - - $res = imagefilledrectangle($this->img, $startXbg, $startYbg, $endXbg, $endYbg, $bgCol); - - if ($o['roundWidth'] > 0) { - - // Top left corner erase - $res = imagefilledrectangle($this->img, $startXfg, $startYfg, $startXfg + $o['roundWidth'] + $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], $bgCol); - // Bottom left corner erase - $res = imagefilledrectangle($this->img, $startXfg, $endYfg - $o['roundWidth'] - $o['lineWidth'], $startXfg + $o['roundWidth'] + $o['lineWidth'], $endYfg, $bgCol); - // Bottom right corner erase - $res = imagefilledrectangle($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], $endXfg, $endYfg, $bgCol); - // Top right corner erase - $res = imagefilledrectangle($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $startYfg, $endXfg, $startYfg + $o['roundWidth'] + $o['lineWidth'], $bgCol); - - // Top left corner arc - $res = imagefilledarc($this->img, $startXfg + $o['roundWidth'] + $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], ($o['roundWidth'] + $o['lineWidth']) * 2, ($o['roundWidth'] + $o['lineWidth']) * 2, 180, 270, $fgCol, IMG_ARC_PIE); - // Top right corner arc - $res = imagefilledarc($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], ($o['roundWidth'] + $o['lineWidth']) * 2, ($o['roundWidth'] + $o['lineWidth']) * 2, 270, 0, $fgCol, IMG_ARC_PIE); - // Bottom right corner arc - $res = imagefilledarc($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], ($o['roundWidth'] + $o['lineWidth']) * 2, ($o['roundWidth'] + $o['lineWidth']) * 2, 0, 90, $fgCol, IMG_ARC_PIE); - // Bottom left corner arc - $res = imagefilledarc($this->img, $startXfg + $o['roundWidth'] + $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], ($o['roundWidth'] + $o['lineWidth']) * 2, ($o['roundWidth'] + $o['lineWidth']) * 2, 90, 180, $fgCol, IMG_ARC_PIE); - - - // Top left corner arc - $res = imagefilledarc($this->img, $startXfg + $o['roundWidth'] + $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], $o['roundWidth'] * 2, $o['roundWidth'] * 2, 180, 270, $bgCol, IMG_ARC_PIE); - // Top right corner arc - $res = imagefilledarc($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $startYfg + $o['roundWidth'] + $o['lineWidth'], $o['roundWidth'] * 2, $o['roundWidth'] * 2, 270, 0, $bgCol, IMG_ARC_PIE); - // Bottom right corner arc - $res = imagefilledarc($this->img, $endXfg - $o['roundWidth'] - $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], $o['roundWidth'] * 2, $o['roundWidth'] * 2, 0, 90, $bgCol, IMG_ARC_PIE); - // Bottom left corner arc - $res = imagefilledarc($this->img, $startXfg + $o['roundWidth'] + $o['lineWidth'], $endYfg - $o['roundWidth'] - $o['lineWidth'], $o['roundWidth'] * 2, $o['roundWidth'] * 2, 90, 180, $bgCol, IMG_ARC_PIE); + * Make an image bevel border. + * + * @param int $size Border size. + * @param mixed $highlight Highlight color. + * @param mixed $shadow Shadow color. + * + * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. + * @access public + */ + function bevel($size = 8, $highlight = 'FFFFFF', $shadow = '000000') + { + $res = $this->_init(); + if (PEAR::isError($res)) { + return $res; + } + + if (!Image_Tools::isGDImageResource($this->resultImage)) { + return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); } + + $highlight = Image_Color::hex2rgb($highlight); + $shadow = Image_Color::hex2rgb($shadow); + + // Create an image resource for highlight. + $iLight = imagecreate($this->_iWidth, $this->_iHeight); + imagecolorallocate($iLight, $highlight[0], $highlight[1], $highlight[2]); + + // Create an image resource for shadow. + $iShadow = imagecreate(1, 1); + imagecolorallocate($iShadow, $shadow[0], $shadow[1], $shadow[2]); + + for ($j = 0; $j < $size; $j++) { + $opacity = 100 - (($j + 1) * (100 / $size)); + imagecopymerge($this->resultImage, $iLight, $j, $j, + 0, 0, 1, $this->_iHeight - (2 * $j), $opacity); + imagecopymerge($this->resultImage, $iLight, $j - 1, $j - 1, + 0, 0, $this->_iWidth - (2 * $j), 1, $opacity); + imagecopymerge($this->resultImage, $iShadow, $this->_iWidth - ($j + 1), $j, + 0, 0, 1, $this->_iHeight - (2 * $j), max(0, $opacity - 10)); + imagecopymerge($this->resultImage, $iShadow, $j, $this->_iHeight - ($j + 1), + 0, 0, $this->_iWidth - (2 * $j), 1, max(0, $opacity - 10)); + } + + // Free highlight and shadow image resources. + imagedestroy($iLight); + imagedestroy($iShadow); + + return true; } + + // }}} + // {{{ render() + + /** + * This method is useless, use directly call for specific border style + * method. + * + * @return bool always TRUE. + * @access protected + */ + function render() + { + return true; + } + + // }}} } -?> + +// }}} + +/* + * Local variables: + * mode: php + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> \ No newline at end of file http://cvs.php.net/diff.php/pear/Image_Tools/generate_package_xml.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Tools/generate_package_xml.php diff -u pear/Image_Tools/generate_package_xml.php:1.1 pear/Image_Tools/generate_package_xml.php:1.2 --- pear/Image_Tools/generate_package_xml.php:1.1 Wed Nov 12 18:11:42 2003 +++ pear/Image_Tools/generate_package_xml.php Sun Oct 2 13:52:59 2005 @@ -1,70 +1,73 @@ <?php +require_once('PEAR/PackageFileManager.php'); - $make = true; +$pkg = new PEAR_PackageFileManager; - echo ini_get('include_path'); +$packagedir = dirname(__FILE__); +$self = basename(__FILE__); - require_once('PEAR/PackageFileManager.php'); +$desc = "Tools collection of common image manipulations."; - $pkg = new PEAR_PackageFileManager; +$options = array( + 'simpleoutput' => true, + 'doctype' => 'D:\Net\www\htdocs\PEAR\PEAR\data\PEAR\package.dtd', + 'package' => 'Image_Tools', + 'license' => 'PHP License', + 'baseinstalldir' => '', + 'version' => '0.3.0', + 'packagedirectory' => $packagedir, + 'pathtopackagefile' => $packagedir, + 'state' => 'alpha', + 'filelistgenerator' => 'file', + 'notes' => 'Hurried release of Image_Tools in order to introduce new API and features', + 'summary' => 'Tools collection for images', + 'description' => $desc, + 'dir_roles' => array( + 'docs' => 'doc', + 'data' => 'data' + ), + 'ignore' => array( + 'package.xml', + '*.tgz', + $self + ) +); - // directory that PEAR CVS is located in - $cvsdir = '/cvs/pear/'; - $packagedir = $cvsdir . 'Image_Tools/'; - $category = 'Image'; - - $e = $pkg->setOptions( - array('baseinstalldir' => '', - 'version' => '0.2', - 'packagedirectory' => $packagedir, - 'pathtopackagefile' => $packagedir, - 'state' => 'alpha', - 'filelistgenerator' => 'cvs', - 'notes' => 'Promised design change. Image_Tools now implements - the factory pattern I promised on pear-dev.', - 'package' => 'Image_Tools', - 'dir_roles' => array( - 'doc' => 'doc'), - 'ignore' => array('package.xml'), - )); - - if (PEAR::isError($e)) { - echo $e->getMessage(); - exit; - } - - $e = $pkg->addDependency('gd', '2', 'has', 'ext'); - if (PEAR::isError($e)) { - echo $e->getMessage(); - exit; - } - - // hack until they get their shit in line with docroot role - $pkg->addRole('tpl', 'php'); - $pkg->addRole('png', 'php'); - $pkg->addRole('gif', 'php'); - $pkg->addRole('jpg', 'php'); - $pkg->addRole('css', 'php'); - $pkg->addRole('js', 'php'); - $pkg->addRole('ini', 'php'); - $pkg->addRole('inc', 'php'); - $pkg->addRole('afm', 'php'); - $pkg->addRole('pkg', 'doc'); - $pkg->addRole('cls', 'doc'); - $pkg->addRole('proc', 'doc'); - $pkg->addRole('sh', 'script'); - - if (isset($make)) { - $e = $pkg->writePackageFile(); - } else { - $e = $pkg->debugPackageFile(); - } - - if (PEAR::isError($e)) { - echo $e->getMessage(); - } - - if (!isset($make)) { - echo '<a href="' . $_SERVER['PHP_SELF'] . '?make=1">Make this file</a>'; - } +$e = $pkg->setOptions($options); +if (PEAR::isError($e)) { + echo $e->getMessage(); + die; +} + +// hack until they get their shit in line with docroot role +$pkg->addRole('tpl', 'php'); +$pkg->addRole('png', 'php'); +$pkg->addRole('gif', 'php'); +$pkg->addRole('jpg', 'php'); +$pkg->addRole('css', 'php'); +$pkg->addRole('js', 'php'); +$pkg->addRole('ini', 'php'); +$pkg->addRole('inc', 'php'); +$pkg->addRole('afm', 'php'); +$pkg->addRole('pkg', 'doc'); +$pkg->addRole('cls', 'doc'); +$pkg->addRole('proc', 'doc'); +$pkg->addRole('txt', 'doc'); +$pkg->addRole('sh', 'script'); + +$pkg->addMaintainer('toby', 'lead', 'Tobias', 'toby@php.net'); +$pkg->addMaintainer('neufeind', 'developer', 'Stefan Neufeind', 'pear.neufeind@speedpartner.de'); +$pkg->addMaintainer('firman', 'lead', 'Firman Wandayandi', 'firman@php.net'); + +$pkg->addDependency('PHP', '4.3.0', 'ge', 'php'); +$pkg->addDependency('PEAR', '1.3.3', 'ge', 'pkg'); +$pkg->addDependency('Image_Color', '1.0.1', 'ge', 'pkg'); +$pkg->addDependency('PHP_Compat', '1.4.1', 'ge', 'pkg'); + +$e = $pkg->addGlobalReplacement('package-info', '@package_version@', 'version'); + +$e = $pkg->writePackageFile(); +if (PEAR::isError($e)) { + echo $e->getMessage(); +} ?> http://cvs.php.net/diff.php/pear/Image_Tools/package.xml?r1=1.2&r2=1.3&ty=u Index: pear/Image_Tools/package.xml diff -u pear/Image_Tools/package.xml:1.2 pear/Image_Tools/package.xml:1.3 --- pear/Image_Tools/package.xml:1.2 Wed Nov 12 18:43:12 2003 +++ pear/Image_Tools/package.xml Sun Oct 2 13:53:00 2005 @@ -1,56 +1,121 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> +<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> -<package version="1.0"> - <name>Image_Tools</name> - <summary>Tool collection for images.</summary> - <description>A collection of comon image manipulations.</description> - <maintainers> - <maintainer> - <user>toby</user> - <name>Tobias Schlitt</name> - <email>tobias@schlitt.info</email> - <role>lead</role> - </maintainer> +<package version="1.0" packagerversion="1.4.1"> + <name>Image_Tools</name> + <summary>Tools collection for images</summary> + <description>Tools collection of common image manipulations. + </description> + <maintainers> + <maintainer> + <user>toby</user> + <name>Tobias</name> + <email>toby@php.net</email> + <role>lead</role> + </maintainer> + <maintainer> + <user>neufeind</user> + <name>Stefan Neufeind</name> + <email>pear.neufeind@speedpartner.de</email> + <role>developer</role> + </maintainer> + <maintainer> + <user>firman</user> + <name>Firman Wandayandi</name> + <email>firman@php.net</email> + <role>lead</role> + </maintainer> </maintainers> - <release> + <release> + <version>0.3.0</version> + <date>2005-10-02</date> + <license>PHP License</license> + <state>alpha</state> + <notes>Hurried release of Image_Tools in order to introduce new API and features + </notes> + <deps> + <dep type="ext" rel="has" version="2">gd</dep> + <dep type="php" rel="ge" version="4.3.0" optional="no"/> + <dep type="pkg" rel="ge" version="1.3.3" optional="no">PEAR</dep> + <dep type="pkg" rel="ge" version="1.0.1" optional="no">Image_Color</dep> + <dep type="pkg" rel="ge" version="1.4.1" optional="no">PHP_Compat</dep> + </deps> + <filelist> + <dir name="/" baseinstalldir=""> + <dir name="docs"> + <dir name="examples"> + <dir name="images"> + <file role="doc" name="mask.png"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="master.PNG"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="pear.PNG"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /docs/examples/images --> + <file role="doc" name="border.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="marquee.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="mask.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="swap.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /docs/examples --> + </dir> <!-- /docs --> + <dir name="Image"> + <dir name="Tools"> + <file role="php" name="Border.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Marquee.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Mask.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Swap.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /Image/Tools --> + <file role="php" name="Tools.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /Image --> + </dir> <!-- / --> + </filelist> + </release> + <changelog> + <release> + <version>0.1</version> + <date>2003-11-04</date> + <license>PHP License</license> + <state>alpha</state> + <notes>3rd try for initial release. All releases before were broken, so I decided to delete all of +them and start new with 0.1 + </notes> + </release> + <release> <version>0.2</version> <date>2003-11-13</date> <license>PHP License</license> <state>alpha</state> <notes>Promised design change. Image_Tools now implements - the factory pattern I promised on pear-dev.</notes> - <deps> - <dep type="ext" rel="has" version="2">gd</dep> - </deps> - <provides type="class" name="Image_Tools" /> - <provides type="function" name="Image_Tools::factory" /> - <provides type="function" name="Image_Tools::setOptions" /> - <provides type="function" name="Image_Tools::setImage" /> - <provides type="class" name="Image_Tools_Border" extends="Image_Tools" /> - <provides type="function" name="Image_Tools_Border::draw" /> - <filelist> - <file role="doc" baseinstalldir="" md5sum="e5931b3e458569abf90b8db58401081e" name="doc/readme.txt"/> - <file role="php" baseinstalldir="" md5sum="9b303992df68456e79cc886b0de44e89" name="Image/Tools.php"/> - <file role="php" baseinstalldir="" md5sum="076e3417d5412764509d054363cf982a" name="Image/Tools/Border.php"/> - <file role="php" baseinstalldir="" md5sum="b8aa85bfeb507b2dabb30ab0cf79861e" name="generate_package_xml.php"/> - </filelist> - </release> - <changelog> - <release> - <version>0.1</version> - <date>2003-11-04</date> - <license>PHP License</license> - <state>alpha</state> - <notes>3rd try for initial release. All releases before were broken, so I decided to delete all of -them and start new with 0.1</notes> - </release> - <release> - <version>0.2</version> - <date>2003-11-13</date> - <license>PHP License</license> - <state>alpha</state> - <notes>Promised design change. Image_Tools now implements - the factory pattern I promised on pear-dev.</notes> - </release> - </changelog> + the factory pattern I promised on pear-dev. + </notes> + </release> + <release> + <version>0.3.0</version> + <date>2005-10-02</date> + <license>PHP License</license> + <state>alpha</state> + <notes>Hurried release of Image_Tools in order to introduce new API and features + </notes> + </release> + </changelog> </package> http://cvs.php.net/co.php/pear/Image_Tools/Image/Tools/Marquee.php?r=1.1&p=1 Index: pear/Image_Tools/Image/Tools/Marquee.php +++ pear/Image_Tools/Image/Tools/Marquee.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ // {{{ Header /** * This is a driver file contains the Image_Tools_Marquee class. * * PHP versions 4 and 5 * * LICENSE: * * The PHP License, version 3.0 * * Copyright (c) 1997-2005 The PHP Group * * This source file is subject to version 3.0 of the PHP license, * that is bundled with this package in the file LICENSE, and is * available through the world-wide-web at the following url: * http://www.php.net/license/3_0.txt. * If you did not receive a copy of the PHP license and are unable to * obtain it through the world-wide-web, please send a note to * license@php.net so we can mail you a copy immediately. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version CVS: $Id: Marquee.php,v 1.1 2005/10/02 17:52:59 firman Exp $ */ // }}} // {{{ Dependencies /** * Load Image_Tools as the base class. */ require_once 'Image/Tools.php'; // }}} // {{{ Constants /** * Image_Tools_Marquee rectangle marquee. * * @name IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE * @access public */ define('IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE', 'marquee_rectangle'); /** * Image_Tools_Marquee single column marquee. * * @name IMAGE_TOOLS_MARQUEE_TYPE_SINGLECOL * @access public */ define('IMAGE_TOOLS_MARQUEE_TYPE_SINGLECOL', 'marquee_singlecol'); /** * Image_Tools_Marquee single row marquee. * * @name IMAGE_TOOLS_MARQUEE_TYPE_SINGLEROW * @access public */ 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 * @access public */ define('IMAGE_TOOLS_MARQUEE_TYPE_POLYGON', 'marquee_polygon'); // }}} // {{{ Class: Image_Tools_Marquee /** * This class provide marquee extraction tool for manipulating an image. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version Release: @package_version@ */ class Image_Tools_Marquee extends Image_Tools { // {{{ Properties /** * Marquee options: * <pre> * sample mixed Sample image, a GD image resource or string filename. * x int X position, this sets X position where marquee will be * placed. * y int Y position, this sets Y position where marquee will be * placed. * </pre> * * @var array * @access protected */ var $options = array( 'image' => null, // Destination image. 'sample' => null, // Sample image. 'x' => 0, // X position. 'y' => 0 // Y position. ); /** * Available options for Image_Tools_Marquee. * * @var array * @access protected */ var $availableOptions = array( 'image' => 'mixed', 'sample' => 'mixed', 'x' => 'int', 'y' => 'int' ); /** * Available methods for Image_Tool_Marquee (only public methods). * * @var array * @access protected */ var $availableMethods = array( 'setRectangleMarquee' => array( 'topLeftX' => 'int', 'topLeftY' => 'int', 'bottomRightX' => 'int', 'bottomRightY' => 'int' ), 'setSingleColMarquee' => array( 'x' => 'int' ), 'setSingleRowMarquee' => array( 'y' => 'int' ) ); /** * Image_Tools_Marquee API version. * * @var string * @access protected */ var $version = '0.1'; /** * Marquee information. * * @var array * @access private */ var $_marquee = array(); /** * Sample image. * * @var resource * @access private */ var $_sample = null; // }}} // {{{ _init() /** * Initialize some internal variables. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access private * @see Image_Tools::createImage() */ function _init() { $res = Image_Tools::createImage($this->options['sample']); if (PEAR::isError($res)) { return $res; } $this->_sample = $res; $res = Image_Tools::createImage($this->options['image']); if (PEAR::isError($res)) { return $res; } $this->resultImage = $res; return true; } // }}} // {{{ 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. * @access public * @see Image_Tools_Marquee::_setMarquee() */ function setRectangleMarquee($topLeftX, $topLeftY, $bottomRightX, $bottomRightY) { if ($topLeftX > $bottomRightX) { $tmp = $topLeftX; $topLeftX = $bottomRightX; $bottomRightX = $tmp; } if ($topLeftY > $bottomRightY) { $tmp = $bottomRightY; $topLeftY = $bottomRightY; $bottomRightY = $tmp; } $points = array($topLeftX, $topLeftY, $bottomRightX, $bottomRightY); $this->_setMarquee(IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE, $points); return true; } // }}} // {{{ setSingleColumnMarquee() /** * Set marquee using single column marquee. * * @param int $x X coordinate. * * @return bool Always TRUE. * @access public * @see Image_Tools_Marquee::_setMarquee() */ function setSingleColumnMarquee($x) { $this->_setMarquee(IMAGE_EXTRACT_MARQUEE_TYPE_SINGLECOL, $x); return true; } // }}} // {{{ setSingleRowMarquee() /** * Set marquee using single row marquee. * * @param int $y Y coordinate. * * @return bool Always TRUE. * @access public * @see Image_Tools_Marquee::_setMarquee() */ function setSingleRowMarquee($y) { $this->_setMarquee(IMAGE_EXTRACT_MARQUEE_TYPE_SINGLEROW, $y); return true; } // }}} // {{{ render() /** * Draw extraction result to resource. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access public * @see Image_Tools_Marquee::_extractRectangle(), * Image_Tools_Marquee::_extractSingleCol(), * Image_Tools_Marquee::_extractSingleRow() */ function render() { $res = $this->_init(); if (PEAR::isError($res)) { return $res; } if (!Image_Tools::isGDImageResource($this->resultImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); } $x = $this->options['x']; $y = $this->options['y']; switch ($this->_marquee['type']) { case IMAGE_TOOLS_MARQUEE_TYPE_RECTANGLE: $this->_extractRectangle($this->resultImage, $x, $y); break; case IMAGE_TOOLS_MARQUEE_TYPE_SINGLECOL: $this->_extractSingleColumn($this->resultImage, $x, $y); break; case IMAGE_TOOLS_MARQUEE_TYPE_SINGLEROW: $this->_extractSingleRow($this->resultImage, $x, $y); break; } return true; } // }}} // {{{ _setMarquee() /** * Set marquee informations. * * @param string $type Marquee type. Use marquee type defined constants. * @param mixed $points Marquee coordinate points. * * @access private */ function _setMarquee($type, $points) { $this->_marquee = array( 'type' => $type, 'points' => $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. * * @access private */ 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; imagecopymerge($img, $this->_sample, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, 100); } // }}} // {{{ _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. * * @access private */ function _extractSingleColumn(&$img, $dstX, $dstY) { $srcX = $this->_marquee['points']; $srcY = 0; $srcW = 1; $srcH = imagesy($this->_sample); imagecopymerge($img, $this->_sample, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, 100); } // }}} // {{{ _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. * * @access private */ function _extractSingleRow(&$img, $dstX, $dstY) { $srcX = 0; $srcY = $this->_marquee['points']; $srcW = imagesx($this->_sample); $srcH = 1; imagecopymerge($img, $this->_sample, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, 100); } // }}} } // }}} /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/Image/Tools/Mask.php?r=1.1&p=1 Index: pear/Image_Tools/Image/Tools/Mask.php +++ pear/Image_Tools/Image/Tools/Mask.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ // {{{ Header /** * This is a driver file contains the Image_Tools_Mask class. * * PHP versions 4 and 5 * * LICENSE: * * The PHP License, version 3.0 * * Copyright (c) 1997-2005 The PHP Group * * This source file is subject to version 3.0 of the PHP license, * that is bundled with this package in the file LICENSE, and is * available through the world-wide-web at the following url: * http://www.php.net/license/3_0.txt. * If you did not receive a copy of the PHP license and are unable to * obtain it through the world-wide-web, please send a note to * license@php.net so we can mail you a copy immediately. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version CVS: $Id: Mask.php,v 1.1 2005/10/02 17:52:59 firman Exp $ */ // }}} // {{{ Dependencies /** * Load Image_Tools as the base class. */ require_once 'Image/Tools.php'; /** * Require for color mixing. Notes: conflict when integrated with * Image_Color v1.0.0 (http://pear.php.net/package/Image_Color). */ require_once 'Image/Color.php'; // }}} // {{{ Class: Image_Tools_Mask /** * This class provide masking tool for manipulating an image. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version Release: @package_version@ */ class Image_Tools_Mask extends Image_Tools { // {{{ Properties /** * Mask options: * <pre> * 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 * mask * </pre> * * @var array * @access protected */ var $options = array( '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. * * @var array * @access protected */ var $availableOptions = array( 'image' => 'mixed', 'mask' => 'mixed', 'sample' => 'mixed', 'mask_color' => 'mixed', 'unmask_color' => 'mixed', 'antialias' => 'bool', 'antialias_factor' => 'int' ); /** * There is no public methods in Image_Tool_Mask. * * @var array * @access protected */ var $availableMethods = array(); /** * Image_Tools_Mask API version. * * @var string * @access protected */ var $version = '0.1'; /** * GD image resource for mask image. * * @var resource * @access private */ var $_maskImage; /** * GD image resource for sample image. * * @var resource * @access private */ var $_sampleImage; // }}} // {{{ _init() /** * Initialize some internal variables. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access private */ function _init() { $res = Image_Tools::createImage($this->options['mask']); if (PEAR::isError($res)) { return $res; } $this->_maskImage = $res; $res = Image_Tools::createImage($this->options['sample']); if (PEAR::isError($res)) { return $res; } $this->_sampleImage = $res; $res = Image_Tools::createImage($this->options['image']); if (PEAR::isError($res)) { return $res; } $this->resultImage = $res; return true; } // }}} // {{{ render() /** * Apply tools to image. * * 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_Error TRUE on success or PEAR_Error on failure. * @access private * @see Image_Tools_Mask::_getNearestColors() */ function render() { $res = $this->_init(); if (PEAR::isError($res)) { return $res; } if (!Image_Tools::isGDImageResource($this->_maskImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_maskImage'); } if (!Image_Tools::isGDImageResource($this->_sampleImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_sampleImage'); } if (!Image_Tools::isGDImageResource($this->resultImage)) { 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); if ($this->options['antialias']) { $closesColors = $this->_getNearestColors(); } else { $closesColors = array($this->options['maskColor']); } imagealphablending($this->resultImage, true); // 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) { continue; } // grab color at x, y and convert to hex color format $index = imagecolorat($this->_maskImage, $x, $y); $maskRGBA = imagecolorsforindex($this->_maskImage, $index); $maskColor = Image_Color::rgb2hex(array_values($maskRGBA)); // check color in closes colors collection if (in_array($maskColor, $closesColors)) { // grab color at x, y from sample image $index = imagecolorat($this->_sampleImage, $x, $y); $sampleRGBA = imagecolorsforindex($this->_sampleImage, $index); // allocate color on destination image $color = imagecolorresolvealpha($this->resultImage, $sampleRGBA['red'], $sampleRGBA['green'], $sampleRGBA['blue'], $sampleRGBA['alpha']); // set a pixel color at destination image imagesetpixel($this->resultImage, $x, $y, $color); } } } return true; } // }}} // {{{ _getNearestColors /** * Get nearest colors between mask color and unmask color using * antialias factor. * * @return array Colors range. * @access private */ function _getNearestColors() { $objColor = new Image_Color; $objColor->setColors($this->options['mask_color'], $this->options['unmask_color']); return $objColor->getRange($this->options['antialias_factor']); } // }}} } // }}} /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/Image/Tools/Swap.php?r=1.1&p=1 Index: pear/Image_Tools/Image/Tools/Swap.php +++ pear/Image_Tools/Image/Tools/Swap.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ // {{{ Header /** * This is a driver file contains the Image_Tools_Swap class. * * PHP versions 4 and 5 * * LICENSE: * * The PHP License, version 3.0 * * Copyright (c) 1997-2005 The PHP Group * * This source file is subject to version 3.0 of the PHP license, * that is bundled with this package in the file LICENSE, and is * available through the world-wide-web at the following url: * http://www.php.net/license/3_0.txt. * If you did not receive a copy of the PHP license and are unable to * obtain it through the world-wide-web, please send a note to * license@php.net so we can mail you a copy immediately. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version CVS: $Id: Swap.php,v 1.1 2005/10/02 17:52:59 firman Exp $ */ // }}} // {{{ Dependencies /** * 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. * * @category Images * @package Image_Tools * @author Firman Wandayandi <firman@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt * The PHP License, version 3.0 * @version Release: @package_version@ */ class Image_Tools_Swap extends Image_Tools { // {{{ Properties /** * Swap options: * <pre> * 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) * </pre> * * @var array * @access protected */ var $options = array( 'image' => null, 'format' => 'RBG' ); /** * Available options for Image_Tools_Swap. * * @var array * @access protected */ var $availableOptions = array( 'image' => 'mixed', 'format' => 'string' ); /** * Available methods for Image_Tool_Swap (only public methods). * * @var array * @access protected */ var $availableMethods = array( 'swapColor' => array( 'format' => 'string', 'rgb' => 'array' ) ); /** * Image_Tools_Swap API version. * * @var string * @access protected */ var $version = '0.1'; // }}} // {{{ _init() /** * Initialize some internal variables. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access private * @see Image_Tools::createImage() */ function _init() { $res = Image_Tools::createImage($this->options['image']); if (PEAR::isError($res)) { return $res; } $this->resultImage = $res; return true; } // }}} // {{{ render() /** * Apply swap color to image and output result. * * This function swap channel color 'R', 'G', 'B' to set format. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access protected */ function render() { $res = $this->_init(); if (PEAR::isError($res)) { return $res; } if (!Image_Tools::isGDImageResource($this->resultImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); } if (!preg_match('@RBG|BGR|BRG|GRB|GBR$@i', $this->options['format'])) { return PEAR::raiseError('Invalid swap format'); } $width = imagesx($this->resultImage); $height = imagesy($this->resultImage); $destImg = imagecreatetruecolor($width, $height); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $index = imagecolorat($this->resultImage, $x, $y); $rgb = imagecolorsforindex($this->resultImage, $index); $rgb = Image_Tools_Swap::swapColor($this->options['format'], $rgb); $color = imagecolorallocate($destImg, $rgb['r'], $rgb['g'], $rgb['b']); imagesetpixel($destImg, $x, $y, $color); } } $this->resultImage = $destImg; return true; } // }}} // {{{ swapColor() /** * 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 * - r, g and b, or * - 0, 1 and 2 * * @return array|PEAR_Error Swapped color channel, an array contains * keys r, g and b on success or PEAR_Error * on failure. * @access public */ function swapColor($format, $rgb) { if (!is_array($rgb)) { return PEAR::raiseError('Type mismatch for argument 2'); } $format = str_split(strtolower($format)); 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'])) { $color = $rgb; } elseif (isset($rgb[0]) && isset($rgb[1]) && isset($rgb[2])) { $color['r'] = $rgb[0]; $color['g'] = $rgb[1]; $color['b'] = $rgb[2]; } else { return PEAR::raiseError('Invalid RGB color'); } return array( $format[0] => $color['r'], $format[1] => $color['g'], $format[2] => $color['b'] ); } // }}} } // }}} /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/package2.xml?r=1.1&p=1 Index: pear/Image_Tools/package2.xml +++ pear/Image_Tools/package2.xml <?xml version="1.0" encoding="UTF-8"?> <package packagerversion="1.4.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>Image_Tools</name> <channel>pear.php.net</channel> <summary>Tools collection for images</summary> <description>Tools collection of common image manipulations. </description> <lead> <name>Tobias</name> <user>toby</user> <email>toby@php.net</email> <active>yes</active> </lead> <lead> <name>Firman Wandayandi</name> <user>firman</user> <email>firman@php.net</email> <active>yes</active> </lead> <developer> <name>Stefan Neufeind</name> <user>neufeind</user> <email>pear.neufeind@speedpartner.de</email> <active>yes</active> </developer> <date>2005-10-02</date> <time>23:36:21</time> <version> <release>0.3.0</release> <api>0.3.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.php.net/license">PHP License</license> <notes>Hurried release of Image_Tools in order to introduce new API and features </notes> <contents> <dir name="/"> <dir name="docs"> <dir name="examples"> <dir name="images"> <file baseinstalldir="" name="mask.png" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="master.PNG" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="pear.PNG" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> <!-- /docs/examples/images --> <file baseinstalldir="" name="border.php" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="marquee.php" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="mask.php" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="swap.php" role="doc"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> <!-- /docs/examples --> </dir> <!-- /docs --> <dir name="Image"> <dir name="Tools"> <file baseinstalldir="" name="Border.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="Marquee.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="Mask.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file baseinstalldir="" name="Swap.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> <!-- /Image/Tools --> <file baseinstalldir="" name="Tools.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> </dir> <!-- /Image --> </dir> <!-- / --> </contents> <dependencies> <required> <php> <min>4.3.0</min> </php> <pearinstaller> <min>1.4.0b1</min> </pearinstaller> <package> <name>PEAR</name> <channel>pear.php.net</channel> <min>1.3.3</min> </package> <package> <name>Image_Color</name> <channel>pear.php.net</channel> <min>1.0.1</min> </package> <package> <name>PHP_Compat</name> <channel>pear.php.net</channel> <min>1.4.1</min> </package> <extension> <name>gd</name> </extension> </required> </dependencies> <phprelease /> <changelog> <release> <version> <release>0.1</release> <api>0.1</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2003-11-04</date> <license uri="http://www.php.net/license">PHP License</license> <notes>3rd try for initial release. All releases before were broken, so I decided to delete all of them and start new with 0.1 </notes> </release> <release> <version> <release>0.2</release> <api>0.2</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2003-11-13</date> <license uri="http://www.php.net/license">PHP License</license> <notes>Promised design change. Image_Tools now implements the factory pattern I promised on pear-dev. </notes> </release> <release> <version> <release>0.3.0</release> <api>0.3.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <date>2005-10-02</date> <license uri="http://www.php.net/license">PHP License</license> <notes>Hurried release of Image_Tools in order to introduce new API and features </notes> </release> </changelog> </package> http://cvs.php.net/co.php/pear/Image_Tools/docs/examples/border.php?r=1.1&p=1 Index: pear/Image_Tools/docs/examples/border.php +++ pear/Image_Tools/docs/examples/border.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */ // CVS: $Id: border.php,v 1.1 2005/10/02 17:53:00 firman Exp $ /** * Load Image_Tools border tool */ require_once 'Image/Tools.php'; $options = array( 'image' => 'images/pear.png', ); // Create new Image_Tools_Border object instance $toolBorder =& Image_Tools::factory('border', $options); if (PEAR::isError($toolBorder)) { die($toolBorder->toString()); } // Create rounded border. $toolBorder->rounded(); // Also try bevel border. #$toolBorder->bevel(); // Apply border to the image and send it to browser $err = $toolBorder->display(); if (PEAR::isError($err)) { die($err->toString()); } /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/docs/examples/marquee.php?r=1.1&p=1 Index: pear/Image_Tools/docs/examples/marquee.php +++ pear/Image_Tools/docs/examples/marquee.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */ // CVS: $Id: marquee.php,v 1.1 2005/10/02 17:53:00 firman Exp $ /** * Load Image_Tools marquee tool */ require_once 'Image/Tools.php'; // Create destination image when masked sample image will be draw. $filename = 'images/master.png'; $destImage = imagecreatefrompng($filename); // Sets sample image, x position and y position. $options = array( 'image' => $destImage, 'sample' => 'images/pear.png', 'x' => 10, 'y' => 10 ); // Create new Image_Tools_Marquee object instance $toolMarquee =& Image_Tools::factory('marquee', $options); if (PEAR::isError($toolMarquee)) { die($toolMarquee->toString()); } // Sets rectangle marquee $toolMarquee->setRectangleMarquee(10, 10, 40, 40); // Apply marquee to the image and send it to browser $err = $toolMarquee->display(); if (PEAR::isError($err)) { die($err->toString()); } /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/docs/examples/mask.php?r=1.1&p=1 Index: pear/Image_Tools/docs/examples/mask.php +++ pear/Image_Tools/docs/examples/mask.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */ // CVS: $Id: mask.php,v 1.1 2005/10/02 17:53:00 firman Exp $ /** * Load Image_Tools. */ require_once 'Image/Tools.php'; // Sets mask and sample image. $options = array( 'image' => 'images/master.png', 'mask' => 'images/mask.png', 'sample' => 'images/pear.png' ); // Create new instance of Image_Mask $toolMask =& Image_Tools::factory('mask', $options); if (PEAR::isError($toolMask)) { die($toolMask->toString()); } // Apply mask and send the result image to browser $err = $toolMask->display(); if (PEAR::isError($err)) { die($err->toString()); } /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/docs/examples/swap.php?r=1.1&p=1 Index: pear/Image_Tools/docs/examples/swap.php +++ pear/Image_Tools/docs/examples/swap.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */ // CVS: $Id: swap.php,v 1.1 2005/10/02 17:53:00 firman Exp $ /** * Require the swap tool */ require_once 'Image/Tools.php'; $options = array( 'image' => 'images/pear.png' ); // Create new Image_Tools_Swap object instance $tool =& Image_Tools::factory('swap', $options); if (PEAR::isError($tool)) { die($tool->toString()); } // Swap the image channel colors and send the result image to browser $err = $tool->display(); if (PEAR::isError($err)) { die($err->toString()); } /* * Local variables: * mode: php * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/Image_Tools/docs/readme.txt?r=1.1&p=1 Index: pear/Image_Tools/docs/readme.txt +++ pear/Image_Tools/docs/readme.txt For actual documentation, please have a look at: http://www.schlitt.info/index.php/content.projects_image_tools