Source for file Thumbnail.php
Documentation is available at Thumbnail.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
* This is a driver file contains the Image_Tools_Thumbnail class
* Copyright (c) 2006-2008 Ildar N. Shaimordanov <ildar-sh@mail.ru>
* This source file is subject to the BSD License license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to pear-dev@list.php.net so we can send you a copy immediately.
* @author Ildar N. Shaimordanov <ildar-sh@mail.ru>
* @copyright Copyright (c) 2006-2008 Ildar N. Shaimordanov <ildar-sh@mail.ru>
* @license http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Thumbnail.php,v 1.8 2008/05/26 06:26:17 firman Exp $
* @since File available since Release 0.4.0
require_once 'Image/Tools.php';
require_once 'Image/Tools/Utils.php';
define('IMAGE_TOOLS_THUMBNAIL_METHOD_SCALE_MAX', 0 );
define('IMAGE_TOOLS_THUMBNAIL_METHOD_SCALE_MIN', 1 );
define('IMAGE_TOOLS_THUMBNAIL_METHOD_CROP', 2 );
define('IMAGE_TOOLS_THUMBNAIL_ALIGN_CENTER', 0 );
define('IMAGE_TOOLS_THUMBNAIL_ALIGN_LEFT', -1 );
define('IMAGE_TOOLS_THUMBNAIL_ALIGN_RIGHT', +1 );
define('IMAGE_TOOLS_THUMBNAIL_ALIGN_TOP', -1 );
define('IMAGE_TOOLS_THUMBNAIL_ALIGN_BOTTOM', +1 );
// {{{ Class: Image_Tools_Thumbnail
* This class provide thumbnail creating tool for manipulating an image
* @author Ildar N. Shaimordanov <ildar-sh@mail.ru>
* @copyright Copyright (c) 2006-2008 Ildar N. Shaimordanov <ildar-sh@mail.ru>
* @license http://www.opensource.org/licenses/bsd-license.php
* @version Release: 1.0.0RC1
* @since Class available since Release 0.4.0
* image mixed Destination image, a filename or an image string data or a GD image resource
* width int Width of thumbnail
* height int Height of thumbnail
* percent number Size of thumbnail per size of original image
* method int Method of thumbnail creating
* halign int Horizontal align
* valign int Vertical align
'method' => IMAGE_TOOLS_THUMBNAIL_METHOD_SCALE_MAX ,
'halign' => IMAGE_TOOLS_THUMBNAIL_ALIGN_CENTER ,
'valign' => IMAGE_TOOLS_THUMBNAIL_ALIGN_CENTER ,
* Available options for Image_Tools_Thumbnail
* Image_Tools_Thumbnail API version.
* Function which called before render.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
* @see Image_Tools::createImage()
// Create the source image
if ( PEAR ::isError ($res) ) {
* Function which called after render.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
* Draw thumbnail result to resource.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
return PEAR ::raiseError ('Invalid image resource');
// Estimate a rectangular portion of the source image and a size of the target image
$Y = $this->_coord ('valign', 'height', $H);
$X = $this->_coord ('halign', 'width', $W);
$height = $this->options['height'];
$W = floor($width * $Hh);
$X = $this->_coord ('halign', 'width', $W);
$H = floor($height * $Ww);
$Y = $this->_coord ('valign', 'height', $H);
$width = floor($height / $H * $W);
$height = floor($width / $W * $H);
// Create the target image
return PEAR ::raiseError ('Cannot initialize new GD image stream');
// enable transparency if supported
// imagealphablending() and imagesavealpha() requires GD 2.0.38
// Copy the source image to the target image
return PEAR ::raiseError ('Cannot resize image');
// Free a memory from the source image and save the resulting thumbnail
* Initialization function.
* Calculate the right coordinate depend on alignment.
* @param string $align Direction of alignment (halign or valign).
* @param string $param Parameter (width or height)
* @param integer $src Source value
function _coord ($align, $param, $src)
$result = ($this->imageInfo[$param] - $src) >> 1;
* c-hanging-comment-ender-p: nil
Documentation generated on Mon, 26 May 2008 06:30:12 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|