class vB_Image_GD extends vB_Image

Image class for GD Image Library

Traits

Constants

GIF

Global image type defines used by serveral functions

JPG

PNG

ALLOW_RANDOM_FONT

These make up the bit field to enable specific parts of image verification

ALLOW_RANDOM_SIZE

ALLOW_RANDOM_SLANT

ALLOW_RANDOM_COLOR

ALLOW_RANDOM_SHAPE

Properties

array $options Options from datastore from vB_Image
array $thumb_extensions from vB_Image
array $info_extensions from vB_Image
array $must_convert_types from vB_Image
array $resize_types from vB_Image
mixed $imageinfo from vB_Image
array $extension_map from vB_Image
$type_to_canonical_extension It's not very clear if $extension_map was supposed to be mimetype => extension, or extension => "type". from vB_Image
$invalid from vB_Image
array $regimageoption from vB_Image
array $imagetype_constants Used to translate from imagetype constants to extension name. from vB_Image
protected $imagefilelocation from vB_Image
protected $thumbcolor

Methods

__sleep()

No description

__wakeup()

No description

void
__construct($options)

Constructor. Sets up resizable types, extensions, etc.

static object
instance($type = 'image')

Select image library

from vB_Image
array
fetchRegimageBackgrounds()

Fetches image files from the backgrounds directory

from vB_Image
array
fetchRegimageFonts()

Fetches True Type fonts from the fonts directory

from vB_Image
bool
fetchMustConvert(string $type)

No description

from vB_Image
bool
isValidInfoExtension(string $extension)

Checks if supplied extension can be used by fetchImageInfo

from vB_Image
bool
isValidResizeType(string $type)

Checks if supplied extension can be resized into a smaller permanent image, not to be used for PSD, PDF, etc as it will lose the original format

from vB_Image
bool
isValidThumbnailExtension(string $extension)

Checks if supplied extension can be used by fetchThumbnail

from vB_Image
bool
fetchImagetypeFromExtension(string $extension)

Checks if supplied extension can be used by fetchThumbnail

from vB_Image
mixed
fetchImageExtension(string $file)

Gets the extension from a given image file or URL.

from vB_Image
getOrientation($location)

No description

from vB_Image
orientationToAnglesCW($orientation)

No description

from vB_Image
orientationToFlipFlop($orientation)

No description

from vB_Image
magicWhiteList($data, $return_extension = false)

No description

from vB_Image
bool
verifyFileHeadersAndExif(string $fileContents, string $location)

Checks for HTML tags that can be exploited via IE, & scripts in exif tags

from vB_Image
bool
verifyImageFile(string $fileContents, string $location)

Checks for HTML tags that can be exploited via IE, scripts in exif tags, and checks file signature against a whitelist of image signatures (currently only support gif, jpg, bmp, tif, psd)

from vB_Image
checkExif($value, $key)

No description

from vB_Image
array
fetchImageInfo($filename)

See function definition in vB_Image

fetchImageInfoForThumbnails($filename)

No description

from vB_Image
array
getImageFromString(string $string, bool $moveabout = true)

See function definition in vB_Image

array
fetchThumbnail(string $filename, string $location, int $maxwidth = 100, int $maxheight = 100, int $quality = 75, bool $labelimage = false, bool $drawborder = false, bool $jpegconvert = false, bool $sharpen = true, owidth $owidth = null, oheight $oheight = null, ofilesize $ofilesize = null)

No description

mixed
cropImg($imgInfo, $maxwidth = 100, $maxheight = 100, $forceResize = false)

Crop the profile image

fetchResizedImageFromFiledata($record, $type)

Fetch a resize image from an existing filedata

from vB_Image
loadFileData($record, $type = vB_Api_Filedata::SIZE_FULL, $includeData = true)

No description

from vB_Image
mixed
getExtensionMap()

standard getter

from vB_Image
mixed
getConvertTypes()

standard getter

from vB_Image
mixed
getInfoExtensions()

standard getter

from vB_Image
mixed
getResizeTypes()

standard getter

from vB_Image
mixed
getThumbExtensions()

standard getter

from vB_Image
bestResize(bool $width, bool $height)

Attempt to resize file if the filesize is too large after an initial resize to max dimensions or the file is already within max dimensions but the filesize is too large

from vB_Image
bool
isImageExtension(String $extension, String $type = vB_Api_Filedata::SIZE_FULL)

Determine if the given extension should be treated as an image for size $type as far as HTML is concerned. These types also align with the cangetimgattachment permission.

from vB_Image
fetchImageExtensions()

No description

from vB_Image
bool
fileLocationIsImage(String $location)

Determine if the given location holds a whitelisted image file. Return false if not an image or not whitelisted.

from vB_Image
getExtensionFromFileheaders($location)

No description

from vB_Image
compareExtensionToFilesignature($extension, $location)

No description

from vB_Image
bool
imageThumbnailSupported(String $extension)

Determine if the given extension can have an image thumbnail. Basically an alias for isValidThumbnailExtension().

from vB_Image
forceRewriteImage($fileContents, $location)

No description

skipWriteImage($fileContents, $location)

No description

loadImage($location)

CALLER MUST CLEAN UP/REMOVE OLD FILE. This is to prevent the image class from removing unknown files that it didn't create.

from vB_Image
__destruct()

No description

from vB_Image
unloadImage()

No description

from vB_Image
bool
canThumbnailPdf()

Returns true if it can detect that the required libraries for supporting jpg thumbnails for PDFs are installed and available.

from vB_Image
fileIsAnimatedGif($filename)

No description

from vB_Image
is_animated_gif($filename)

No description

from vB_Image
fileContentIsAnimatedGif($filecontent)

No description

from vB_Image
printImage($image, $type = 'JPEG', $headers = true, $quality = 75, $filename = null)

No description

void
unsharpmask(object $finalimage, int $amount = 50, radius $radius = 1, threshold $threshold = 0)

Sharpen an image

resource
fetchImageResource(int $width, int $height)

Create blank image

string
annotategd(resource $image, string $letter, boolean $random = true)

Return a letter position command

string
annotatettf($image, $letter, $font, $random = true)

Return a letter position command

object
flipimage(image $image)

mirror an image horizontally. Can be extended to other flips but this is all we need for now

object
swirl(image $image, float $degree = 0.005, bool $randirection = true)

Apply a swirl/twirl filter to an image

image
wave(image $image, int $wave = 10, bool $randirection = true)

Apply a wave filter to an image

image
blur(image $image, int $radius = 0.5)

Apply a blur filter to an image

orientImageInternalGD(Resource $image, int $orientation)

Rotate/flip/flop image from $fileContents as specified by 'orientation' exif tag. Caller must perform file-write using the image resource.

Details

in vB_Trait_NoSerialize at line 15
__sleep()

in vB_Trait_NoSerialize at line 20
__wakeup()

at line 42
void __construct($options)

Constructor. Sets up resizable types, extensions, etc.

Parameters

$options

Return Value

void

in vB_Image at line 250
static object instance($type = 'image')

Select image library

Parameters

$type

Return Value

object

in vB_Image at line 282
protected array fetchRegimageBackgrounds()

Fetches image files from the backgrounds directory

Return Value

array

in vB_Image at line 307
protected array fetchRegimageFonts()

Fetches True Type fonts from the fonts directory

Return Value

array

in vB_Image at line 333
bool fetchMustConvert(string $type)

Parameters

string $type Type of image from $info_extensions

Return Value

bool

in vB_Image at line 346
bool isValidInfoExtension(string $extension)

Checks if supplied extension can be used by fetchImageInfo

Parameters

string $extension Extension of file

Return Value

bool

in vB_Image at line 360
bool isValidResizeType(string $type)

Checks if supplied extension can be resized into a smaller permanent image, not to be used for PSD, PDF, etc as it will lose the original format

Parameters

string $type Type of image from $info_extensions

Return Value

bool

in vB_Image at line 374
bool isValidThumbnailExtension(string $extension)

Checks if supplied extension can be used by fetchThumbnail

Parameters

string $extension Extension of file

Return Value

bool

in vB_Image at line 388
bool fetchImagetypeFromExtension(string $extension)

Checks if supplied extension can be used by fetchThumbnail

Parameters

string $extension Extension of file

Return Value

bool

in vB_Image at line 409
mixed fetchImageExtension(string $file)

Gets the extension from a given image file or URL.

Parameters

string $file Could be a URL string or full path filename

Return Value

mixed array of thumbnail ext

in vB_Image at line 450
protected getOrientation($location)

Parameters

$location

in vB_Image at line 475
protected orientationToAnglesCW($orientation)

Parameters

$orientation

in vB_Image at line 503
protected orientationToFlipFlop($orientation)

Parameters

$orientation

in vB_Image at line 542
protected magicWhiteList($data, $return_extension = false)

Parameters

$data
$return_extension

in vB_Image at line 619
bool verifyFileHeadersAndExif(string $fileContents, string $location)

Checks for HTML tags that can be exploited via IE, & scripts in exif tags

Parameters

string $fileContents Contents of the file e.g. file_get_contents($location)
string $location Full filepah

Return Value

bool

in vB_Image at line 675
bool verifyImageFile(string $fileContents, string $location)

Checks for HTML tags that can be exploited via IE, scripts in exif tags, and checks file signature against a whitelist of image signatures (currently only support gif, jpg, bmp, tif, psd)

Parameters

string $fileContents Contents of the file e.g. file_get_contents($location)
string $location Full filepah

Return Value

bool True if nothing was detected, false if headers were not found, throws an exception if possible nasty was detected.

in vB_Image at line 712
protected checkExif($value, $key)

Parameters

$value
$key

at line 846
array fetchImageInfo($filename)

See function definition in vB_Image

Parameters

$filename

Return Value

array [0] int width [1] int height [2] string type ('GIF', 'JPEG', 'PNG', 'PSD', 'BMP', 'TIFF',) (and so on) [scenes] int scenes [channels] int Number of channels (GREYSCALE = 1, RGB = 3, CMYK = 4) [bits] int Number of bits per pixel [library] string Library Identifier

in vB_Image at line 741
fetchImageInfoForThumbnails($filename)

Parameters

$filename

at line 368
array getImageFromString(string $string, bool $moveabout = true)

See function definition in vB_Image

Parameters

string $string string String to output
bool $moveabout moveabout move text about

Return Value

array Array containing imageInfo: filedata, filesize, filetype and htmltype

at line 1235
array fetchThumbnail(string $filename, string $location, int $maxwidth = 100, int $maxheight = 100, int $quality = 75, bool $labelimage = false, bool $drawborder = false, bool $jpegconvert = false, bool $sharpen = true, owidth $owidth = null, oheight $oheight = null, ofilesize $ofilesize = null)

Parameters

string $filename filename filename of the source file
string $location location location of the source file
int $maxwidth maxwidth
int $maxheight maxheight
int $quality quality Jpeg Quality
bool $labelimage labelimage Include image dimensions and filesize on thumbnail
bool $drawborder drawborder Draw border around thumbnail
bool $jpegconvert jpegconvert
bool $sharpen sharpen
owidth $owidth
oheight $oheight
ofilesize $ofilesize

Return Value

array

See also

vB_Image::fetchThumbnail

at line 1471
mixed cropImg($imgInfo, $maxwidth = 100, $maxheight = 100, $forceResize = false)

Crop the profile image

@param array $imgInfo contains all the required information * filename * extension * filedata * width * height * x1 * y1

Parameters

$imgInfo
$maxwidth
$maxheight
$forceResize

Return Value

mixed array of data with the cropped image info: * width * height * filedata * filesize * dateline * imageerror (not used) * filename (if the filename was changed during processing)

in vB_Image at line 812
fetchResizedImageFromFiledata($record, $type)

Fetch a resize image from an existing filedata

Parameters

$record
$type

in vB_Image at line 889
loadFileData($record, $type = vB_Api_Filedata::SIZE_FULL, $includeData = true)

Parameters

$record
$type
$includeData

in vB_Image at line 1021
mixed getExtensionMap()

standard getter

Return Value

mixed array of file extension-to-type maps , like 'gif' => "GIF' *

in vB_Image at line 1031
mixed getConvertTypes()

standard getter

Return Value

mixed array of must conver types

in vB_Image at line 1041
mixed getInfoExtensions()

standard getter

Return Value

mixed array of valid extensions

in vB_Image at line 1051
mixed getResizeTypes()

standard getter

Return Value

mixed array of resize types

in vB_Image at line 1061
mixed getThumbExtensions()

standard getter

Return Value

mixed array of thumbnail ext

in vB_Image at line 1072
bestResize(bool $width, bool $height)

Attempt to resize file if the filesize is too large after an initial resize to max dimensions or the file is already within max dimensions but the filesize is too large

Parameters

bool $width Has the image already been resized once?
bool $height Attempt a resize

in vB_Image at line 1133
bool isImageExtension(String $extension, String $type = vB_Api_Filedata::SIZE_FULL)

Determine if the given extension should be treated as an image for size $type as far as HTML is concerned. These types also align with the cangetimgattachment permission.

Parameters

String $extension File extension, usually from filedata.extension.
String $type One of vB_Api_Filedata::SIZE_X strings

Return Value

bool

in vB_Image at line 1176
fetchImageExtensions()

in vB_Image at line 1205
bool fileLocationIsImage(String $location)

Determine if the given location holds a whitelisted image file. Return false if not an image or not whitelisted.

Parameters

String $location Full file path

Return Value

bool

in vB_Image at line 1296
getExtensionFromFileheaders($location)

Parameters

$location

in vB_Image at line 1301
compareExtensionToFilesignature($extension, $location)

Parameters

$extension
$location

in vB_Image at line 1323
bool imageThumbnailSupported(String $extension)

Determine if the given extension can have an image thumbnail. Basically an alias for isValidThumbnailExtension().

Mostly for the PDF to image thumbnail handling for imagemagick.

Parameters

String $extension File extension, usually from filedata.extension.

Return Value

bool

at line 951
protected forceRewriteImage($fileContents, $location)

Parameters

$fileContents
$location

at line 935
protected skipWriteImage($fileContents, $location)

Parameters

$fileContents
$location

in vB_Image at line 1341
loadImage($location)

CALLER MUST CLEAN UP/REMOVE OLD FILE. This is to prevent the image class from removing unknown files that it didn't create.

Parameters

$location

in vB_Image at line 1456
__destruct()

in vB_Image at line 1461
unloadImage()

in vB_Image at line 1478
bool canThumbnailPdf()

Returns true if it can detect that the required libraries for supporting jpg thumbnails for PDFs are installed and available.

Currently used by upgrade scripts to check if GhostScript is installed and configured in the delegates file when using ImageMagick library.

Return Value

bool

in vB_Image at line 1483
fileIsAnimatedGif($filename)

Parameters

$filename

in vB_Image at line 1499
protected is_animated_gif($filename)

Parameters

$filename

in vB_Image at line 1595
fileContentIsAnimatedGif($filecontent)

Parameters

$filecontent

at line 87
protected printImage($image, $type = 'JPEG', $headers = true, $quality = 75, $filename = null)

Parameters

$image
$type
$headers
$quality
$filename

at line 201
protected void unsharpmask(object $finalimage, int $amount = 50, radius $radius = 1, threshold $threshold = 0)

Sharpen an image

Parameters

object $finalimage finalimage
int $amount float
radius $radius float
threshold $threshold float

Return Value

void

at line 495
protected resource fetchImageResource(int $width, int $height)

Create blank image

Parameters

int $width width Width of image
int $height height Height of image

Return Value

resource

at line 514
protected string annotategd(resource $image, string $letter, boolean $random = true)

Return a letter position command

Parameters

resource $image image Image to annotate
string $letter letter Character to position
boolean $random random Apply effects

Return Value

string

at line 559
protected string annotatettf($image, $letter, $font, $random = true)

Return a letter position command

Parameters

$image
$letter
$font
$random

Return Value

string

at line 652
protected object flipimage(image $image)

mirror an image horizontally. Can be extended to other flips but this is all we need for now

Parameters

image $image image Image file to convert

Return Value

object image

at line 677
protected object swirl(image $image, float $degree = 0.005, bool $randirection = true)

Apply a swirl/twirl filter to an image

Parameters

image $image image Image file to convert
float $degree output Degree of twirl
bool $randirection randirection Randomize direction of swirl (clockwise/counterclockwise)

Return Value

object image

at line 736
protected image wave(image $image, int $wave = 10, bool $randirection = true)

Apply a wave filter to an image

Parameters

image $image image Image to convert
int $wave wave Amount of wave to apply
bool $randirection randirection Randomize direction of wave

Return Value

image

at line 797
protected image blur(image $image, int $radius = 0.5)

Apply a blur filter to an image

Parameters

image $image image Image to convert
int $radius radius Radius of blur

Return Value

image

at line 1046
protected orientImageInternalGD(Resource $image, int $orientation)

Rotate/flip/flop image from $fileContents as specified by 'orientation' exif tag. Caller must perform file-write using the image resource.

Parameters

Resource $image GD Image resource from $this->getImage(). Return value of one of the imagecreatefrom_x() GD functions.
int $orientation image orientation from exif data, typically result of getOrientation($location)