Source for file Transform.php
Documentation is available at Transform.php
/***********************************************************************
** Title.........: Image Transformation Interface
** Author........: Xiang Wei ZHUO <wei@zhuo.org>
** Filename......: Transform.php
** Last changed..: 30 Aug 2003
** Notes.........: Orginal is from PEAR
- create unique filename in a particular directory,
used for temp image files.
- added cropping to GD, NetPBM, ImageMagick
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.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. |
// +----------------------------------------------------------------------+
// | Authors: Peter Bowyer <peter@mapledesign.co.uk> |
// | Alan Knowles <alan@akbkhome.com> |
// | Vincent Oostindie <vincent@sunlight.tmfweb.nl> |
// +----------------------------------------------------------------------+
// Image Transformation interface
* The main "Image_Resize" class is a container and base class which
* provides the static methods for creating Image objects as well as
* some utility functions (maths) common to all parts of Image Resize.
* The object model of DB is as follows (indentation means inheritance):
* Image_Resize The base for each Image implementation. Provides default
* | implementations (in OO lingo virtual methods) for
* | the actual Image implementations as well as a bunch of
* +-Image_GD The Image implementation for the PHP GD extension . Inherits
* When calling DB::setup for GD images the object returned is an
* instance of this class.
* @author Peter Bowyer <peter@mapledesign.co.uk>
* Type of the image file (eg. jpg, gif png ...)
* Original image width in x direction
* Original image width in y direction
* New image width in x direction
* New image width in y direction
* Path the the library used
* e.g. /usr/local/ImageMagick/bin/ or
* Flag to warn if image has been resized more than once before displaying
* Create a new Image_resize object
* @param string $driver name of driver class to initialize
* @return mixed a newly created Image_Transform object, or a PEAR
* @see Image_Transform::setOption()
die("No image library specified... aborting. You must call ::factory() with one parameter, the library to load.");
$this->uid =
md5($_SERVER['REMOTE_ADDR']);
include_once "$driver.php";
$classname =
"Image_Transform_Driver_{$driver}";
* Resize the Image in the X and/or Y direction
* If either is 0 it will be scaled proportionally
* @param mixed $new_x (0, number, percentage 10% or 0.1)
* @param mixed $new_y (0, number, percentage 10% or 0.1)
* @return mixed none or PEAR_error
function resize($new_x =
0, $new_y =
0)
// 0 means keep original size
$new_x =
(0 ==
$new_x) ?
$this->img_x :
$this->_parse_size($new_x, $this->img_x);
$new_y =
(0 ==
$new_y) ?
$this->img_y :
$this->_parse_size($new_y, $this->img_y);
// Now do the library specific resizing.
return $this->_resize($new_x, $new_y);
* Scale the image to have the max x dimension specified.
* @param int $new_x Size to scale X-dimension to
return $this->_resize($new_x, $new_y);
* Scale the image to have the max y dimension specified.
* @param int $new_y Size to scale Y-dimension to
return $this->_resize($new_x, $new_y);
* Scale Image to a maximum or percentage
* @param mixed (number, percentage 10% or 0.1)
* @return mixed none or PEAR_error
* Scales an image to a percentage of its original size. For example, if
* my image was 640x480 and I called scaleByPercentage(10) then the image
* would be resized to 64x48
* @param int $size Percentage of original size to scale to
} // End scaleByPercentage
* Scales an image to a factor of its original size. For example, if
* my image was 640x480 and I called scaleByFactor(0.5) then the image
* would be resized to 320x240.
* @param float $size Factor of original size to scale to
return $this->_resize($new_x, $new_y);
* Scales an image so that the longest side has this dimension.
* @param int $size Max dimension in pixels
return $this->_resize($new_x, $new_y);
$data =
@GetImageSize($image);
#1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order,
# 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC
echo
("We do not recognize this image format");
echo
("Cannot fetch image or images details.");
* Parse input and convert
* If either is 0 it will be scaled proportionally
* @param mixed $new_size (0, number, percentage 10% or 0.1)
* @return mixed none or PEAR_error
function _parse_size($new_size, $old_size)
$new_size =
$new_size /
100;
} elseif ($new_size ==
0) {
return (int)
round($new_size *
$old_size, 0);
//delete old tmp files, and allow only 1 file per remote host.
while (false !==
($entry =
$d->read())) {
//echo filemtime($this->directory.'/'.$entry)."<br>";
if (substr($entry, 1, $id_length) ==
$id)
//make sure the the unique temp file does not exists
* @param int $size dimension to set
* @since 29/05/02 13:36:31
* @param int $size dimension to set
* @since 29/05/02 13:36:31
* @param int $size dimension to set
* @since 29/05/02 13:36:31
* @param int $size dimension to set
* @since 29/05/02 13:36:31
* Get the type of the image being manipulated
* @return string $this->type the image type
* @return string web-safe image type
* Place holder for the real resize method
* used by extended methods to do the resizing
return null; //PEAR::raiseError("No Resize method exists", true);
* Place holder for the real load method
* used by extended methods to do the resizing
function load($filename) {
return null; //PEAR::raiseError("No Load method exists", true);
* Place holder for the real display method
* used by extended methods to do the resizing
function display($type, $quality) {
return null; //PEAR::raiseError("No Display method exists", true);
* Place holder for the real save method
* used by extended methods to do the resizing
function save($filename, $type, $quality) {
return null; //PEAR::raiseError("No Save method exists", true);
* Place holder for the real free method
* used by extended methods to do the resizing
return null; //PEAR::raiseError("No Free method exists", true);
* Reverse of rgb2colorname.
* Reverse of rgb2colorname.
return strlen($color)>
6?
false:
$color;
/* Methods to add to the driver classes in the future */
return null; //PEAR::raiseError("No addText method exists", true);
return null; //PEAR::raiseError("No AddDropShadow method exists", true);
return null; //PEAR::raiseError("No addBorder method exists", true);
return null; //PEAR::raiseError("No crop method exists", true);
return null; //PEAR::raiseError("No gamma method exists", true);
Documentation generated on Mon, 05 May 2008 16:23:52 +0400 by phpDocumentor 1.4.0