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 Ildar N. Shaimordanov <ildar-sh@mail.ru>
* Redistribution and use in source and binary forms, with or without
* modification, are permitted under the terms of the BSD License.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* @author Ildar N. Shaimordanov <ildar-sh@mail.ru>
* @copyright Copyright (c) 2006 Ildar N. Shaimordanov <ildar-sh@mail.ru>
* @license http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Thumbnail.php,v 1.3 2006/11/23 22:17:31 firman Exp $
require_once 'Image/Tools.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 Ildar N. Shaimordanov <ildar-sh@mail.ru>
* @license http://www.opensource.org/licenses/bsd-license.php
* @version Release: 0.4.1
* 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.
* Draw thumbnail result to resource.
* @return bool|PEAR_ErrorTRUE on success or PEAR_Error on failure.
// Create the source image
if ( PEAR ::isError ($source) ) {
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');
// 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
function _coord ($align, $param, $src)
$result = ($this->imageInfo[$param] - $src) >> 1;
* c-hanging-comment-ender-p: nil
Documentation generated on Thu, 23 Nov 2006 18:00:08 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|