Class GdThumb

Description

GdThumb Class Definition

This is the GD Implementation of the PHP Thumb library.

Located in /GdThumb.inc.php (line 33)

ThumbBase
   |
   --GdThumb
Variable Summary
Method Summary
 GdThumb __construct (string $fileName, [ $options = array()], [ $isDataStream = false])
 void __destruct ()
 GdThumb adaptiveResize ( $width,  $height, int $maxWidth, int $maxHeight)
 array calcHeight (int $width, int $height)
 void calcImageSize (int $width, int $height)
 void calcImageSizePercent (int $width, int $height)
 void calcImageSizeStrict (int $width, int $height)
 array calcPercent (int $width, int $height)
 array calcWidth (int $width, int $height)
 GdThumb crop (int $startX, int $startY, int $cropWidth, int $cropHeight)
 GdThumb cropFromCenter (int $cropWidth, [int $cropHeight = null])
 void determineFormat ()
 string getImageAsString ()
 void getMaxHeight ()
 void getMaxWidth ()
 void getOldImage ()
 void getOptions ()
 void getPercent ()
 void getWorkingImage ()
 void preserveAlpha ()
 GdThumb resize ([int $maxWidth = 0], [int $maxHeight = 0])
 GdThumb resizePercent ([int $percent = 0])
 void rotateImage ([string $direction = 'CW'])
 GdThumb rotateImageNDegrees (int $degrees)
 GdThumb save (string $fileName, [string $format = null])
 void setCurrentDimensions (object $currentDimensions)
 void setMaxHeight (object $maxHeight)
 void setMaxWidth (object $maxWidth)
 void setNewDimensions (object $newDimensions)
 void setOldImage (object $oldImage)
 void setOptions ([array $options = array()])
 void setPercent (object $percent)
 void setWorkingImage (object $workingImage)
 GdThumb show ([bool $rawData = false])
Variables
array $currentDimensions (line 52)

The current dimensions of the image

  • access: protected
int $maxHeight (line 80)

The maximum height an image can be after resizing (in pixels)

  • access: protected
int $maxWidth (line 74)

The maximum width an image can be after resizing (in pixels)

  • access: protected
array $newDimensions (line 58)

The new, calculated dimensions of the image

  • access: protected
resource $oldImage (line 40)

The prior image (before manipulation)

  • access: protected
array $options (line 68)

The options for this class

This array contains various options that determine the behavior in various functions throughout the class. Functions note which specific option key / values are used in their documentation

  • access: protected
int $percent (line 86)

The percentage to resize the image by

  • access: protected
resource $workingImage (line 46)

The working image (used during manipulation)

  • access: protected

Inherited Variables

Inherited from ThumbBase

ThumbBase::$errorMessage
ThumbBase::$fileName
ThumbBase::$format
ThumbBase::$hasError
ThumbBase::$imported
ThumbBase::$importedFunctions
ThumbBase::$isDataStream
ThumbBase::$remoteImage
Methods
Constructor __construct (line 94)

Class Constructor

  • access: public
GdThumb __construct (string $fileName, [ $options = array()], [ $isDataStream = false])
  • string $fileName
  • $options
  • $isDataStream

Redefinition of:
ThumbBase::__construct()
Class constructor
Destructor __destruct (line 136)

Class Destructor

  • access: public
void __destruct ()
adaptiveResize (line 237)

Adaptively Resizes the Image

This function attempts to get the image to as close to the provided dimensions as possible, and then crops the remaining overflow (from the center) to get the image to be the size specified

  • access: public
GdThumb adaptiveResize ( $width,  $height, int $maxWidth, int $maxHeight)
  • int $maxWidth
  • int $maxHeight
  • $width
  • $height
calcHeight (line 916)

Calculates a new width and height for the image based on $this->maxWidth and the provided dimensions

  • access: protected
array calcHeight (int $width, int $height)
  • int $width
  • int $height
calcImageSize (line 955)

Calculates the new image dimensions

These calculations are based on both the provided dimensions and $this->maxWidth and $this->maxHeight

  • access: protected
void calcImageSize (int $width, int $height)
  • int $width
  • int $height
calcImageSizePercent (line 1048)

Calculates new dimensions based on $this->percent and the provided dimensions

  • access: protected
void calcImageSizePercent (int $width, int $height)
  • int $width
  • int $height
calcImageSizeStrict (line 992)

Calculates new image dimensions, not allowing the width and height to be less than either the max width or height

  • access: protected
void calcImageSizeStrict (int $width, int $height)
  • int $width
  • int $height
calcPercent (line 935)

Calculates a new width and height for the image based on $this->percent and the provided dimensions

  • access: protected
array calcPercent (int $width, int $height)
  • int $width
  • int $height
calcWidth (line 897)

Calculates a new width and height for the image based on $this->maxWidth and the provided dimensions

  • access: protected
array calcWidth (int $width, int $height)
  • int $width
  • int $height
crop (line 424)

Vanilla Cropping - Crops from x,y with specified width and height

  • access: public
GdThumb crop (int $startX, int $startY, int $cropWidth, int $cropHeight)
  • int $startX
  • int $startY
  • int $cropWidth
  • int $cropHeight
cropFromCenter (line 387)

Crops an image from the center with provided dimensions

If no height is given, the width will be used as a height, thus creating a square crop

  • access: public
GdThumb cropFromCenter (int $cropWidth, [int $cropHeight = null])
  • int $cropWidth
  • int $cropHeight
determineFormat (line 1062)

Determines the file format by mime-type

This function will throw exceptions for invalid images / mime-types

  • access: protected
void determineFormat ()
getCurrentDimensions (line 733)

Returns $currentDimensions.

void getCurrentDimensions ()
getImageAsString (line 609)

Returns the Working Image as a String

This function is useful for getting the raw image data as a string for storage in a database, or other similar things.

  • access: public
string getImageAsString ()
getMaxHeight (line 754)

Returns $maxHeight.

void getMaxHeight ()
getMaxWidth (line 775)

Returns $maxWidth.

void getMaxWidth ()
getNewDimensions (line 796)

Returns $newDimensions.

void getNewDimensions ()
getOldImage (line 848)

Returns $oldImage.

void getOldImage ()
getOptions (line 817)

Returns $options.

void getOptions ()
getPercent (line 827)

Returns $percent.

void getPercent ()
getWorkingImage (line 869)

Returns $workingImage.

void getWorkingImage ()
preserveAlpha (line 1152)

Preserves the alpha or transparency for PNG and GIF files

Alpha / transparency will not be preserved if the appropriate options are set to false. Also, the GIF transparency is pretty skunky (the results aren't awesome), but it works like a champ... that's the nature of GIFs tho, so no huge surprise.

This functionality was originally suggested by commenter Aimi (no links / site provided) - Thanks! :)

  • access: protected
void preserveAlpha ()
resize (line 164)

Resizes an image to be no larger than $maxWidth or $maxHeight

If either param is set to zero, then that dimension will not be considered as a part of the resize. Additionally, if $this->options['resizeUp'] is set to true (false by default), then this function will also scale the image up to the maximum dimensions provided.

  • access: public
GdThumb resize ([int $maxWidth = 0], [int $maxHeight = 0])
  • int $maxWidth: The maximum width of the image in pixels
  • int $maxHeight: The maximum height of the image in pixels
resizePercent (line 336)

Resizes an image by a given percent uniformly

Percentage should be whole number representation (i.e. 1-100)

  • access: public
GdThumb resizePercent ([int $percent = 0])
  • int $percent
rotateImage (line 512)

Rotates image either 90 degrees clockwise or counter-clockwise

  • access: public
void rotateImage ([string $direction = 'CW'])
  • string $direction
rotateImageNDegrees (line 532)

Rotates image specified number of degrees

  • access: public
GdThumb rotateImageNDegrees (int $degrees)
  • int $degrees
save (line 635)

Saves an image

This function will make sure the target directory is writeable, and then save the image.

If the target directory is not writeable, the function will try to correct the permissions (if allowed, this is set as an option ($this->options['correctPermissions']). If the target cannot be made writeable, then a RuntimeException is thrown.

TODO: Create additional paramter for color matte when saving images with alpha to non-alpha formats (i.e. PNG => JPG)

  • access: public
GdThumb save (string $fileName, [string $format = null])
  • string $fileName: The full path and filename of the image to save
  • string $format: The format to save the image in (optional, must be one of [GIF,JPG,PNG]
setCurrentDimensions (line 744)

Sets $currentDimensions.

void setCurrentDimensions (object $currentDimensions)
  • object $currentDimensions
setMaxHeight (line 765)

Sets $maxHeight.

void setMaxHeight (object $maxHeight)
  • object $maxHeight
setMaxWidth (line 786)

Sets $maxWidth.

void setMaxWidth (object $maxWidth)
  • object $maxWidth
setNewDimensions (line 807)

Sets $newDimensions.

void setNewDimensions (object $newDimensions)
  • object $newDimensions
setOldImage (line 859)

Sets $oldImage.

void setOldImage (object $oldImage)
  • object $oldImage
setOptions (line 691)

Sets $this->options to $options

  • access: public
void setOptions ([array $options = array()])
  • array $options
setPercent (line 838)

Sets $percent.

void setPercent (object $percent)
  • object $percent
setWorkingImage (line 880)

Sets $workingImage.

void setWorkingImage (object $workingImage)
  • object $workingImage
show (line 565)

Shows an image

This function will show the current image by first sending the appropriate header for the format, and then outputting the image data. If headers have already been sent, a runtime exception will be thrown

  • access: public
GdThumb show ([bool $rawData = false])
  • bool $rawData: Whether or not the raw image stream should be output
verifyFormatCompatiblity (line 1110)

Makes sure the correct GD implementation exists for the file type

  • access: protected
void verifyFormatCompatiblity ()

Inherited Methods

Inherited From ThumbBase

 ThumbBase::__construct()
 ThumbBase::fileExistsAndReadable()
 ThumbBase::getErrorMessage()
 ThumbBase::getFileName()
 ThumbBase::getFormat()
 ThumbBase::getHasError()
 ThumbBase::getImported()
 ThumbBase::getImportedFunctions()
 ThumbBase::importPlugins()
 ThumbBase::imports()
 ThumbBase::setErrorMessage()
 ThumbBase::setFileName()
 ThumbBase::setFormat()
 ThumbBase::setHasError()
 ThumbBase::triggerError()
 ThumbBase::__call()

Documentation generated on Thu, 05 Nov 2009 00:32:58 -0800 by phpDocumentor 1.4.3