GraphicsUtil Class Reference

Detailed Description

GraphicsUtil provides support for graphic manipulation.

Note
This class requires ImageWorkshop, GifFrameExtractor and GifCreator
Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 34 of file GraphicsUtil.php.

Public Member Functions

 getErrorMsg ()
 
 isImage ($imgname)
 
 isValidImageDimension ($imgname, $width, $height, $exact=true)
 
 isValidImageWidth ($imgname, $width, $exact=true)
 
 isValidImageHeight ($imgname, $height, $exact=true)
 
 fitIntoSquare ($srcName, $maxDimension)
 
 createThumbnail ($srcName, $destName, $width, $height)
 
 cropImage ($srcName, $destName, $width, $height, $x=null, $y=null)
 
 createBlackWhiteImage ($srcName, $destName)
 
 processImageFunction ($srcName, $destName, $function, $params)
 
 renderText ($text, $fontfile, $fontsize, $color, $bgcolor, $filename, $width=null, $height=null, $x=null, $y=null, $angle=0)
 

Member Function Documentation

getErrorMsg ( )

Get last error message.

Returns
The error string

Definition at line 42 of file GraphicsUtil.php.

isImage (   $imgname)

Check if a given file is an image.

Parameters
$imgnameName of the imagefile to check
Returns
Boolean whether the file is an image

Definition at line 51 of file GraphicsUtil.php.

isValidImageDimension (   $imgname,
  $width,
  $height,
  $exact = true 
)

Check image dimensions.

Parameters
$imgnameName of the imagefile to check
$widthWidth of the image, -1 means don't care
$heightHeight of the image, -1 means don't care
$exactBoolean whether the image should match the dimension exactly or might be smaller (default: true)
Returns
Boolean whether the image meets the dimensions, error string provided by getErrorMsg()

Definition at line 68 of file GraphicsUtil.php.

isValidImageWidth (   $imgname,
  $width,
  $exact = true 
)

Check image width.

Parameters
$imgnameName of the imagefile to check
$widthWidth of the image
$exactBoolean whether the image width should match exactly or might be smaller (default: true)
Returns
Boolean whether the image width meets the criteria, error string provided by getErrorMsg()
Note
This method returns true if the file does not exist.

Definition at line 82 of file GraphicsUtil.php.

isValidImageHeight (   $imgname,
  $height,
  $exact = true 
)

Check image height.

Parameters
$imgnameName of the imagefile to check
$heightHeight of the image
$exactBoolean whether the image height should match exactly or might be smaller (default: true)
Returns
Boolean whether the image width meets the criteria, error string provided by getErrorMsg()
Note
This method returns true if the file does not exist.

Definition at line 108 of file GraphicsUtil.php.

fitIntoSquare (   $srcName,
  $maxDimension 
)

Calculate image dimension to fit into a square, preserving the aspect ratio.

Parameters
$srcNameThe source file name
$maxDimensionThe maximum dimension the image should have (either width or height)
Returns
Array with width and height value or null, on error, error string provided by getErrorMsg()

Definition at line 132 of file GraphicsUtil.php.

createThumbnail (   $srcName,
  $destName,
  $width,
  $height 
)

Create a thumbnail of an image file.

Parameters
$srcNameThe source file name
$destNameThe destination file name
$widthThe width of the thumbnail (maybe null)
$heightThe height of the thumbnail (maybe null)
Returns
Boolean whether the operation succeeded, error string provided by getErrorMsg()
Note
: supported image formats are GIF, JPG, PNG if only width or height are given the other dimension is calculated to preserve the aspect

Definition at line 167 of file GraphicsUtil.php.

cropImage (   $srcName,
  $destName,
  $width,
  $height,
  $x = null,
  $y = null 
)

Crop an image to the given size starting from the middle of a given start point.

Parameters
$srcNameThe source file name
$destNameThe destination file name
$widthThe width of the cropped image (maybe null)
$heightThe height of the cropped image (maybe null)
$xThe start point x coordinate (maybe null, default null)
$yThe start point y coordinate (maybe null, default null)
Returns
Boolean whether the operation succeeded, error string provided by getErrorMsg()
Note
: supported image formats are GIF, JPG, PNG if only width or height are given the other dimension is taken from the original image

Definition at line 190 of file GraphicsUtil.php.

createBlackWhiteImage (   $srcName,
  $destName 
)

Create a black and white copy of an image.

Parameters
$srcNameThe source file name
$destNameThe destination file name

Definition at line 211 of file GraphicsUtil.php.

processImageFunction (   $srcName,
  $destName,
  $function,
  $params 
)

Process the given function on the given source image (supports animated gifs) and save the result in the given destination image.

Parameters
$srcNameThe source file name
$destNameThe destination file name
$functionThe name of the function
$paramsThe paremeters to be passed to the function

Definition at line 229 of file GraphicsUtil.php.

renderText (   $text,
  $fontfile,
  $fontsize,
  $color,
  $bgcolor,
  $filename,
  $width = null,
  $height = null,
  $x = null,
  $y = null,
  $angle = 0 
)

Render a text to an image.

Using the default parameters the text will be rendered into a box that fits the text. If the width parameter is not null and the text exceeds the width, the text will be wrapped and the height parameter will be used as lineheight. Wrapping code is from http://de.php.net/manual/de/function.imagettfbbox.php#60673

Parameters
$textThe text to render
$fontfileThe ttf font file to use
$fontsizeThe font size to use (in pixels)
$colorThe color to use for the text (as HEX value)
$bgcolorThe color to use for the background (as HEX value)
$filenameThe name of the file to write to
$widthThe width of the image (or null if it should fit the text) (default: null)
$heightThe height of the image (or null if it should fit the text) (default: null)
$xThe x offset of the text (or null if it should be centered) (default: null)
$yThe y offset of the text (or null if the baseline should be the image border) (default: null)
$angleThe angle of the text (optional, default: 0)
Returns
Boolean whether the operation succeeded, error string provided by getErrorMsg()

Definition at line 272 of file GraphicsUtil.php.