Class GdThumb

Description

GdThumb Class Definition

This is the GD Implementation of the PHP Thumb library.

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

ThumbBase
   |
   --GdThumb
Variable Summary
Method Summary
GdThumb __construct (string $fileName, [ $options = array()])
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 ()
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)
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::$remoteImage
Methods
Constructor __construct (line 94)

Class Constructor

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

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

Class Destructor

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

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 880)

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 919)

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 1012)

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 956)

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 899)

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 861)

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 418)

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 381)

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 1026)

Determines the file format by mime-type

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

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

Returns $currentDimensions.

void getCurrentDimensions ()
getMaxHeight (line 718)

Returns $maxHeight.

void getMaxHeight ()
getMaxWidth (line 739)

Returns $maxWidth.

void getMaxWidth ()
getNewDimensions (line 760)

Returns $newDimensions.

void getNewDimensions ()
getOldImage (line 812)

Returns $oldImage.

void getOldImage ()
getOptions (line 781)

Returns $options.

void getOptions ()
getPercent (line 791)

Returns $percent.

void getPercent ()
getWorkingImage (line 833)

Returns $workingImage.

void getWorkingImage ()
preserveAlpha (line 1108)

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 158)

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 330)

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 506)

Rotates image either 90 degrees clockwise or counter-clockwise

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

Rotates image specified number of degrees

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

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 708)

Sets $currentDimensions.

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

Sets $maxHeight.

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

Sets $maxWidth.

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

Sets $newDimensions.

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

Sets $oldImage.

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

Sets $this->options to $options

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

Sets $percent.

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

Sets $workingImage.

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

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 ()
verifyFormatCompatiblity (line 1068)

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 Tue, 09 Aug 2011 09:04:57 +0200 by phpDocumentor 1.4.3