Image_Transform
[ class tree: Image_Transform ] [ index: Image_Transform ] [ all elements ]

Class: Image_Transform

Source Location: /Image_Transform-0.9.5/Image/Transform.php

Class Overview


Base class with factory method for backend driver


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 2002-2007 The PHP Group

Variables

Methods


Child classes:

Image_Transform_Driver_Cairowrapper
Cairo implementation for Image_Transform package using pecl's cairo_wrapper extension.
Image_Transform_Driver_GD
GD implementation for Image_Transform package
Image_Transform_Driver_NetPBM
NetPBM implementation for Image_Transform package
Image_Transform_Driver_Imlib
Performs image manipulation with the imlib library.
Image_Transform_Driver_IM
ImageMagick binaries implementation for Image_Transform package
Image_Transform_Driver_Imagick3
imagick PECL extension implementation for Image_Transform package
Image_Transform_Driver_Imagick2
imagick PECL extension implementation for Image_Transform package

Inherited Variables

Inherited Methods


Class Details

[line 82]
Base class with factory method for backend driver

The main "Image_Transform" class is a container and base class which provides a static method for creating an Image object as well as some utility functions (maths) common to all parts of Image_Transform.



[ Top ]


Class Variables

$default_text_params = array(
        'text' => 'Default text',
        'x'     => 10,
        'y'     => 20,
        'color' => 'red',
        'font'  => 'Arial.ttf',
        'size'  => 12,
        'angle' => 0,
        'resize_first' => false
    )

[line 178]

Default parameters used in the addText methods.

Type:   mixed


[ Top ]

$image =  ''

[line 88]

Name of the image file

Type:   string


[ Top ]

$img_x =  ''

[line 100]

Original image width in x direction

Type:   int


[ Top ]

$img_y =  ''

[line 106]

Original image width in y direction

Type:   int


[ Top ]

$keep_settings_on_save =  false

[line 150]

Flag for whether settings should be discarded on saving/display of image
  • See: Image_Transform::keepSettingsOnSave

Type:   bool


[ Top ]

$lib_path =  ''

[line 125]

Path to the library used

e.g. /usr/local/ImageMagick/bin/ or /usr/local/netpbm/


Type:   mixed


[ Top ]

$new_x =  ''

[line 112]

New image width in x direction

Type:   int


[ Top ]

$new_y =  ''

[line 118]

New image width in y direction

Type:   int


[ Top ]

$resized =  false

[line 131]

Flag to warn if image has been resized more than once before displaying or saving.

Type:   mixed


[ Top ]

$type =  ''

[line 94]

Type of the image file (eg. jpg, gif png ...)

Type:   string


[ Top ]

$_options = array(
        'quality'     => 75,
        'scaleMethod' => 'smooth',
        'canvasColor' => array(255, 255, 255),'pencilColor'=>array(0,0,0),'textColor'=>array(0,0,0))

[line 137]

  • Var: General options
  • Access: protected

Type:   array


[ Top ]

$_programs = array()

[line 173]

associative array that tracks existence of programs

(for drivers using shell interface and a tiny performance improvement if the clearstatcache() is used)

  • Access: protected

Type:   array


[ Top ]

$_supported_image_types = array()

[line 157]

Supported image types
  • Access: protected

Type:   array


[ Top ]



Method Detail

addBorder   [line 1178]

void addBorder( )


Overridden in child classes as:

Image_Transform_Driver_GD::addBorder()
Adds a border of constant width around an image

[ Top ]

addDropShadow   [line 1172]

void addDropShadow( )


[ Top ]

addText   [line 1166]

void addText( )

Methods to add to the driver classes in the future

Overridden in child classes as:

Image_Transform_Driver_GD::addText()
addText
Image_Transform_Driver_NetPBM::addText()
adds text to an image
Image_Transform_Driver_Imlib::addText()
Adds text to the image. Note that the angle should be one of the following constants: IMLIB_TEXT_TO_RIGHT, IMLIB_TEXT_TO_LEFT, IMLIB_TEXT_TO_DOWN, IMLIB_TEXT_TO_UP, IMLIB_TEXT_TO_ANGLE
Image_Transform_Driver_IM::addText()
addText
Image_Transform_Driver_Imagick3::addText()
Adds text to the image
Image_Transform_Driver_Imagick2::addText()
addText

[ Top ]

canvasResize   [line 1201]

void canvasResize( )


[ Top ]

colorarray2colorhex   [line 1115]

mixed colorarray2colorhex( array $color)

Converts an array of RGB value into a #FFFFFF format color.

Parameters:

array   $color   —  3-element array with 0-255 values

[ Top ]

colorhex2colorarray   [line 1086]

array colorhex2colorarray( string $colorhex)

Converts a color string into an array of RGB values

Parameters:

string   $colorhex   —  A color following the #FFFFFF format

[ Top ]

crop   [line 1195]

mixed crop( int $width, int $height, [int $x = 0], [int $y = 0])

Crops an image
  • Return: TRUE or a PEAR_Error object on error
  • Access: public

Overridden in child classes as:

Image_Transform_Driver_GD::crop()
Crops image by size and start coordinates
Image_Transform_Driver_NetPBM::crop()
Crop an image
Image_Transform_Driver_Imlib::crop()
Crops the current image to a specified height and width
Image_Transform_Driver_IM::crop()
Crop image
Image_Transform_Driver_Imagick3::crop()
Crops the image
Image_Transform_Driver_Imagick2::crop()
Crops the image

Parameters:

int   $width   —  Cropped image width
int   $height   —  Cropped image height
int   $x   —  X-coordinate to crop at
int   $y   —  Y-coordinate to crop at

[ Top ]

display   [line 1021]

PEAR_error display( string $type, [mixed $quality = null])

Outputs the image to standard output

Place holder for the real display method used by extended methods to do the resizing

  • Access: public

Overridden in child classes as:

Image_Transform_Driver_GD::display()
Displays image without saving and lose changes.
Image_Transform_Driver_NetPBM::display()
Display image without saving and lose changes
Image_Transform_Driver_Imlib::display()
Display image without saving and lose changes
Image_Transform_Driver_IM::display()
Display image without saving and lose changes
Image_Transform_Driver_Imagick3::display()
Displays image without saving and lose changes
Image_Transform_Driver_Imagick2::display()
Displays image without saving and lose changes

Parameters:

string   $type   —  Format of image to save as
mixed   $quality   —  Format-dependent

[ Top ]

factory   [line 201]

object an &factory( [string $driver = ''])

Creates a new Image_Transform object

Parameters:

string   $driver   —  name of driver class to initialize. If no driver is specified the factory will attempt to use 'Imagick' first then 'GD' second, then 'Imlib' last

[ Top ]

fit   [line 474]

bool|PEAR_Error fit( integer $width, integer $height)

Fits the image in the specified box size

If the image is bigger than the box specified by $width and $height, it will be scaled down to fit inside of it. If the image is smaller, nothing is done.

  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

integer   $width   —  Width of the box in pixels
integer   $height   —  Height of the box in pixels

[ Top ]

fitOnCanvas   [line 501]

unknown fitOnCanvas( unknown_type $width, unknown_type $height, [unknown_type $posn = 'center'])

This works as per fit, but creates the canvas of size $width x $height and positions the resized image on it, by default in the centre.

Parameters:

unknown_type   $width   — 
unknown_type   $height   — 
unknown_type   $posn   — 

[ Top ]

fitX   [line 519]

bool|PEAR_Error fitX( integer $width)

Fits the image in the specified width

If the image is wider than the width specified by $width, it will be scaled down to fit inside of it. If the image is smaller, nothing is done.

  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

integer   $width   —  Maximum width in pixels

[ Top ]

fitY   [line 536]

bool|PEAR_Error fitY( integer $height)

Fits the image in the specified height

If the image is taller than the height specified by $height, it will be scaled down to fit inside of it. If the image is smaller, nothing is done.

  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

integer   $height   —  Maximum height in pixels

[ Top ]

flip   [line 1256]

TRUE flip( )

Vertical mirroring

Overridden in child classes as:

Image_Transform_Driver_Cairowrapper::flip()
Mirrors the image vertically Uses an affine transformation matrix to flip the image.
Image_Transform_Driver_GD::flip()
Vertical mirroring
Image_Transform_Driver_NetPBM::flip()
Vertical mirroring
Image_Transform_Driver_Imlib::flip()
Vertical mirroring
Image_Transform_Driver_IM::flip()
Vertical mirroring
Image_Transform_Driver_Imagick3::flip()
Vertical mirroring
Image_Transform_Driver_Imagick2::flip()
Vertical mirroring

[ Top ]

free   [line 1069]

PEAR_error free( )

Releases resource

Place holder for the real free method used by extended methods to do the resizing

  • Access: public

Overridden in child classes as:

Image_Transform_Driver_Cairowrapper::free()
Frees cairo handles
Image_Transform_Driver_GD::free()
Destroys image handle
Image_Transform_Driver_NetPBM::free()
Destroy image handle
Image_Transform_Driver_Imlib::free()
Destroy image handle
Image_Transform_Driver_IM::free()
Destroy image handle
Image_Transform_Driver_Imagick3::free()
Destroy image handle
Image_Transform_Driver_Imagick2::free()
Destroy image handle

[ Top ]

gamma   [line 1215]

mixed gamma( [float $outputgamma = 1.0])

Corrects the gamma of an image
  • Return: TRUE or a PEAR_error object on error
  • Access: public

Overridden in child classes as:

Image_Transform_Driver_GD::gamma()
Adjusts the image gamma
Image_Transform_Driver_NetPBM::gamma()
Adjust the image gamma
Image_Transform_Driver_IM::gamma()
Adjust the image gamma
Image_Transform_Driver_Imagick3::gamma()
Adjusts the image gamma
Image_Transform_Driver_Imagick2::gamma()
Adjusts the image gamma

Parameters:

float   $outputgamma   —  Gamma correction factor

[ Top ]

getHandle   [line 818]

resource getHandle( )

Returns the image handle so that one can further try to manipulate the image
  • Access: public

Overridden in child classes as:

Image_Transform_Driver_Cairowrapper::getHandle()
Returns the surface of the image so it can be modified further
Image_Transform_Driver_GD::getHandle()
Returns the GD image handle

[ Top ]

getImageHeight   [line 904]

int getImageHeight( )

Returns the image height
  • Return: the width of the image
  • Access: public

[ Top ]

getImageSize   [line 916]

array getImageSize( )

Returns the image size and extra format information
  • Return: The width and height of the image
  • See: PHP::getimagesize()
  • Access: public

[ Top ]

getImageType   [line 830]

string getImageType( )

Returns the type of the image being manipulated
  • Return: the image type
  • Access: public

[ Top ]

getImageWidth   [line 893]

int getImageWidth( )

Returns the image width
  • Return: the width of the image
  • Access: public

[ Top ]

getMimeType   [line 845]

string getMimeType( [string $type = null])

Returns the MIME type of the image being manipulated

Parameters:

string   $type   —  Image type to get MIME type for

[ Top ]

getNewImageHeight   [line 878]

int getNewImageHeight( )

Return new image Y

This function will retrieve the new image 'Y' and return it's value if it's set.

  • Return: The new height of the image.
  • Access: public

[ Top ]

getNewImageWidth   [line 859]

int getNewImageWidth( )

Returns the new image width

This function returns the width of the new image.

  • Return: The width of the new image.
  • Access: public

[ Top ]

getTempDir   [line 1132]

string getTempDir( )

Returns the temp directory according to either the TMP, TMPDIR, or TEMP env variables. If these are not set it will also check for the existence of /tmp, %WINDIR%\temp
  • Return: The system tmp directory
  • Access: public

[ Top ]

getTempFile   [line 1146]

string getTempFile( [string $dirname = null])

Returns a temporary filename using tempnam() and the above getTmpDir() function.
  • Return: Filename and path of the tmp file
  • Access: public

Parameters:

string   $dirname   —  Optional directory name for the tmp file

[ Top ]

getWebSafeFormat   [line 935]

string getWebSafeFormat( )

This looks at the current image type and attempts to determine which

web-safe format will be most suited. It does not work brilliantly with *.png images, because it is very difficult to know whether they are 8-bit or greater. Guess I need to have fatter code here :-)

  • Return: web-safe image type
  • Access: public

[ Top ]

grayscale   [line 1280]

mixed grayscale( )

Converts an image into greyscale colors

[ Top ]

greyscale   [line 1268]

mixed greyscale( )

Converts an image into greyscale colors
  • Return: TRUE or a PEAR error object on error
  • Access: public

Overridden in child classes as:

Image_Transform_Driver_GD::greyscale()
Converts the image to greyscale
Image_Transform_Driver_NetPBM::greyscale()
Converts an image into greyscale colors
Image_Transform_Driver_IM::greyscale()
Convert the image to greyscale
Image_Transform_Driver_Imagick3::greyscale()
Converts the image to greyscale

[ Top ]

intersects   [line 1341]

bool|PEAR_Error intersects( int $width, int $height, int $x, int $y)

Checks if the rectangle passed intersects with the current image
  • Return: TRUE if intersects, FALSE if not, and PEAR_Error on error
  • Access: public

Parameters:

int   $width   —  Width of rectangle
int   $height   —  Height of rectangle
int   $x   —  X-coordinate
int   $y   —  Y-coordinate

[ Top ]

isError   [line 279]

mixed &isError( [object $error = null])

Returns/sets an error when the instance couldn't initialize properly
  • Return: FALSE or PEAR_Error object
  • Access: protected

Parameters:

object   $error   —  PEAR_Error object when setting an error

[ Top ]

keepSettingsOnSave   [line 1156]

void keepSettingsOnSave( $bool)


Parameters:

   $bool   — 

[ Top ]

load   [line 1003]

PEAR_error load( string $filename)

Loads an image file to work with

Place holder for the real load method used by extended methods to do the resizing

  • Access: public

Overridden in child classes as:

Image_Transform_Driver_Cairowrapper::load()
Loads an image from file
Image_Transform_Driver_GD::load()
Loads an image from file
Image_Transform_Driver_NetPBM::load()
Load image
Image_Transform_Driver_Imlib::load()
Load image
Image_Transform_Driver_IM::load()
Load an image.
Image_Transform_Driver_Imagick3::load()
Loads an image
Image_Transform_Driver_Imagick2::load()
Loads an image

Parameters:

string   $filename   —  Full name of file

[ Top ]

mirror   [line 1243]

mixed mirror( )

Horizontal mirroring

Overridden in child classes as:

Image_Transform_Driver_Cairowrapper::mirror()
Mirrors the image horizontally.
Image_Transform_Driver_GD::mirror()
Horizontal mirroring
Image_Transform_Driver_NetPBM::mirror()
Horizontal mirroring
Image_Transform_Driver_Imlib::mirror()
Horizontal mirroring
Image_Transform_Driver_IM::mirror()
Horizontal mirroring
Image_Transform_Driver_Imagick3::mirror()
Horizontal mirroring
Image_Transform_Driver_Imagick2::mirror()
Horizontal mirroring

[ Top ]

normalize   [line 986]

PEAR_error normalize( )

Normalizes the colors, gamma and other properties of an image (this should give a result equivalent to a Photoshop autolevels)
  • Access: public

[ Top ]

resize   [line 299]

mixed resize( [mixed $new_x = 0], [mixed $new_y = 0], [array $options = null])

Resizes the image in the X and/or Y direction(s)

If either is 0 it will keep the original size for that dimension

  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

mixed   $new_x   —  (0, number, percentage 10% or 0.1)
mixed   $new_y   —  (0, number, percentage 10% or 0.1)
array   $options   —  Options

[ Top ]

rotate   [line 1230]

bool|PEAR_Error rotate( float $angle, [mixed $options = null])

Rotates the image clockwise
  • Return: TRUE on success, PEAR_Error object on error
  • Access: public

Overridden in child classes as:

Image_Transform_Driver_GD::rotate()
Rotates image by the given angle
Image_Transform_Driver_GD1::rotate()
Image_Transform_Driver_NetPBM::rotate()
Rotates the image
Image_Transform_Driver_Imlib::rotate()
Rotate image by the given angle
Image_Transform_Driver_IM::rotate()
rotate
Image_Transform_Driver_Imagick3::rotate()
Rotates the current image
Image_Transform_Driver_Imagick2::rotate()
Rotates the current image Note: color mask are currently not supported

Parameters:

float   $angle   —  Angle of rotation in degres
mixed   $options   —  Rotation options

[ Top ]

save   [line 1054]

PEAR_error save( string $filename, string $type, [mixed $quality = null])

Saves image to file

Place holder for the real save method used by extended methods to do the resizing

  • Access: public

Overridden in child classes as:

Image_Transform_Driver_Cairowrapper::save()
Saves the scaled image into a file.
Image_Transform_Driver_GD::save()
Saves the image to a file
Image_Transform_Driver_NetPBM::save()
Save the image file
Image_Transform_Driver_Imlib::save()
Save the image file. Determines what type of image to save based on extension.
Image_Transform_Driver_IM::save()
Save the image file
Image_Transform_Driver_Imagick3::save()
Saves the image to a file
Image_Transform_Driver_Imagick2::save()
Saves the image to a file

Parameters:

string   $filename   —  Filename to save image to
string   $type   —  Format of image to save as
mixed   $quality   —  Format-dependent

[ Top ]

scale   [line 374]

mixed scale( mixed $size)

Scales an image by a percentage, factor or a given length

This method preserves the aspect ratio


Parameters:

mixed   $size   —  (number, percentage 10% or 0.1)

[ Top ]

scaleByFactor   [line 410]

mixed scaleByFactor( float $size)

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.
  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

float   $size   —  Factor of original size to scale to

[ Top ]

scaleByLength   [line 456]

mixed scaleByLength( int $size)

Alias for scaleMaxLength

Parameters:

int   $size   —  Max dimension in pixels

[ Top ]

scaleByPercentage   [line 395]

mixed scaleByPercentage( int $size)

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
  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

int   $size   —  Percentage of original size to scale to

[ Top ]

scaleByX   [line 323]

mixed scaleByX( int $new_x)

Scales the image to the specified width

This method preserves the aspect ratio

  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

int   $new_x   —  Size to scale X-dimension to

[ Top ]

scaleByXY   [line 338]

void scaleByXY( [ $new_x = 0], [ $new_y = 0], [ $options = null])

Alias for resize()

Parameters:

   $new_x   — 
   $new_y   — 
   $options   — 

[ Top ]

scaleByY   [line 353]

mixed scaleByY( int $new_y)

Scales the image to the specified height.

This method preserves the aspect ratio

  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

int   $new_y   —  Size to scale Y-dimension to

[ Top ]

scaleMaxLength   [line 431]

mixed scaleMaxLength( int $size)

Scales an image so that the longest side has the specified dimension.

This method preserves the aspect ratio

  • Return: TRUE or PEAR_Error object on error
  • Access: public

Parameters:

int   $size   —  Max dimension in pixels

[ Top ]

setOption   [line 551]

void setOption( string $name, mixed $value)

Sets one options

Parameters:

string   $name   —  Name of option
mixed   $value   —  Value of option

[ Top ]

setOptions   [line 568]

void setOptions( array $options)

Sets multiple options at once

Associative array of options:

  • quality (Integer: 0: poor - 100: best)
  • scaleMethod ('smooth', 'pixel')

  • Access: public

Parameters:

array   $options   —  Array of options

[ Top ]

supportsType   [line 1036]

TRUE supportsType( string $type, [string $mode = 'rw'])

Returns if the driver supports a given image type
  • Return: if type (and mode) is supported FALSE otherwise
  • Access: public

Parameters:

string   $type   —  Image type (GIF, PNG, JPEG...)
string   $mode   —  'r' for read, 'w' for write, 'rw' for both

[ Top ]

_convert_image_type   [line 661]

mixed _convert_image_type( mixed $type)

Returns the matching IMAGETYPE_* constant for a given image type
  • Return: string or integer or input on error
  • See: PHP_Compat::image_type_to_mime_type()
  • Access: protected

Parameters:

mixed   $type   —  String (GIF, JPG,...)

[ Top ]

_getColor   [line 1295]

array _getColor( string $colorOf, [array $options = array()], [array $default = array(0, 0, 0)])

Returns a color option
  • Return: an RGB color array
  • Access: protected

Parameters:

string   $colorOf   —  one of 'canvasColor', 'pencilColor', 'fontColor'
array   $options   —  configuration options
array   $default   —  default value to return if color not found

[ Top ]

_getOption   [line 1323]

mixed _getOption( string $name, [array $options = array()], [mixed $default = null])

Returns an option
  • Return: the option
  • Access: protected

Parameters:

string   $name   —  name of option
array   $options   —  local override option array
mixed   $default   —  default value to return if option is not found

[ Top ]

_get_default_text_params   [line 749]

array _get_default_text_params( )

Returns the current value of $this->default_text_params.
  • Return: The current text parameters
  • Access: protected

[ Top ]

_get_image_details   [line 583]

mixed _get_image_details( string $image)

Sets the image type (in lowercase letters), the image height and width.

Parameters:

string   $image   —  Image filename

[ Top ]

_parse_size   [line 714]

mixed _parse_size( mixed $new_size, int $old_size)

Parses input for number format and convert

If either parameter is 0 it will be scaled proportionally

  • Return: Integer or PEAR_error
  • Access: protected

Parameters:

mixed   $new_size   —  (0, number, percentage 10% or 0.1)
int   $old_size   — 

[ Top ]

_prepare_cmd   [line 957]

string _prepare_cmd( string $path, string $command, [string $args = ''])

Handles space in path and Windows/UNIX difference
  • Return: A prepared string suitable for exec()
  • Access: protected

Parameters:

string   $path   —  Base dir
string   $command   —  Command to execute
string   $args   —  Arguments to pass to the command

[ Top ]

_resize   [line 973]

PEAR_error _resize( )

Place holder for the real resize method used by extended methods to do the resizing
  • Access: protected

Overridden in child classes as:

Image_Transform_Driver_Cairowrapper::_resize()
Resize the image
Image_Transform_Driver_GD::_resize()
Resize Action
Image_Transform_Driver_Imagick3::_resize()
Resizes the image
Image_Transform_Driver_Imagick2::_resize()
Resize Action

[ Top ]

_rotation_angle   [line 737]

float _rotation_angle( float $angle)

Returns an angle between 0 and 360 from any angle value
  • Return: the angle
  • Access: protected

Parameters:

float   $angle   —  The angle to normalize

[ Top ]

_set_img_x   [line 763]

void _set_img_x( int $size)

Sets the image width
  • Since: 29/05/02 13:36:31
  • Access: protected

Parameters:

int   $size   —  dimension to set

[ Top ]

_set_img_y   [line 777]

void _set_img_y( int $size)

Sets the image height
  • Since: 29/05/02 13:36:31
  • Access: protected

Parameters:

int   $size   —  dimension to set

[ Top ]

_set_new_x   [line 791]

void _set_new_x( int $size)

Sets the new image width
  • Since: 29/05/02 13:36:31
  • Access: protected

Parameters:

int   $size   —  dimension to set

[ Top ]

_set_new_y   [line 805]

void _set_new_y( int $size)

Sets the new image height
  • Since: 29/05/02 13:36:31
  • Access: protected

Parameters:

int   $size   —  dimension to set

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:48:01 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.