abstract class vB_Image

Class for image processing

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
array $thumb_extensions
array $info_extensions
array $must_convert_types
array $resize_types
mixed $imageinfo
array $extension_map
$type_to_canonical_extension It's not very clear if $extension_map was supposed to be mimetype => extension, or extension => "type".
$invalid
array $regimageoption
array $imagetype_constants Used to translate from imagetype constants to extension name.
protected $imagefilelocation

Methods

__sleep()

No description

__wakeup()

No description

void
__construct($options)

Constructor Don't allow direct construction of this abstract class Sets registry

static object
instance($type = 'image')

Select image library

array
fetchRegimageBackgrounds()

Fetches image files from the backgrounds directory

array
fetchRegimageFonts()

Fetches True Type fonts from the fonts directory

bool
fetchMustConvert(string $type)

No description

bool
isValidInfoExtension(string $extension)

Checks if supplied extension can be used by fetchImageInfo

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

bool
isValidThumbnailExtension(string $extension)

Checks if supplied extension can be used by fetchThumbnail

bool
fetchImagetypeFromExtension(string $extension)

Checks if supplied extension can be used by fetchThumbnail

mixed
fetchImageExtension(string $file)

Gets the extension from a given image file or URL.

getOrientation($location)

No description

orientationToAnglesCW($orientation)

No description

orientationToFlipFlop($orientation)

No description

magicWhiteList($data, $return_extension = false)

No description

bool
verifyFileHeadersAndExif(string $fileContents, string $location)

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

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)

checkExif($value, $key)

No description

array
fetchImageInfo($filename)

Retrieve info about image

fetchImageInfoForThumbnails($filename)

No description

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

Output an image based on a string

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)

Returns an array containing a thumbnail, creation time, thumbnail size and any errors

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

Crop the profile image

fetchResizedImageFromFiledata($record, $type)

Fetch a resize image from an existing filedata

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

No description

mixed
getExtensionMap()

standard getter

mixed
getConvertTypes()

standard getter

mixed
getInfoExtensions()

standard getter

mixed
getResizeTypes()

standard getter

mixed
getThumbExtensions()

standard getter

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

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.

fetchImageExtensions()

No description

bool
fileLocationIsImage(String $location)

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

getExtensionFromFileheaders($location)

No description

compareExtensionToFilesignature($extension, $location)

No description

bool
imageThumbnailSupported(String $extension)

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

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.

__destruct()

No description

unloadImage()

No description

bool
canThumbnailPdf()

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

fileIsAnimatedGif($filename)

No description

is_animated_gif($filename)

No description

fileContentIsAnimatedGif($filecontent)

No description

Details

in vB_Trait_NoSerialize at line 15
__sleep()

in vB_Trait_NoSerialize at line 20
__wakeup()

at line 148
void __construct($options)

Constructor Don't allow direct construction of this abstract class Sets registry

Parameters

$options

Return Value

void

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

Select image library

Parameters

$type

Return Value

object

at line 282
protected array fetchRegimageBackgrounds()

Fetches image files from the backgrounds directory

Return Value

array

at line 307
protected array fetchRegimageFonts()

Fetches True Type fonts from the fonts directory

Return Value

array

at line 333
bool fetchMustConvert(string $type)

Parameters

string $type Type of image from $info_extensions

Return Value

bool

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

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

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

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

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

at line 450
protected getOrientation($location)

Parameters

$location

at line 475
protected orientationToAnglesCW($orientation)

Parameters

$orientation

at line 503
protected orientationToFlipFlop($orientation)

Parameters

$orientation

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

Parameters

$data
$return_extension

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

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.

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

Parameters

$value
$key

at line 736
array fetchImageInfo($filename)

Retrieve info about 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

at line 741
fetchImageInfoForThumbnails($filename)

Parameters

$filename

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

Output an image based on a string

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

Returns an array containing a thumbnail, creation time, thumbnail size and any errors

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

at line 803
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)

at line 812
fetchResizedImageFromFiledata($record, $type)

Fetch a resize image from an existing filedata

Parameters

$record
$type

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

Parameters

$record
$type
$includeData

at line 1021
mixed getExtensionMap()

standard getter

Return Value

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

at line 1031
mixed getConvertTypes()

standard getter

Return Value

mixed array of must conver types

at line 1041
mixed getInfoExtensions()

standard getter

Return Value

mixed array of valid extensions

at line 1051
mixed getResizeTypes()

standard getter

Return Value

mixed array of resize types

at line 1061
mixed getThumbExtensions()

standard getter

Return Value

mixed array of thumbnail ext

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

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

at line 1176
fetchImageExtensions()

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

at line 1296
getExtensionFromFileheaders($location)

Parameters

$location

at line 1301
compareExtensionToFilesignature($extension, $location)

Parameters

$extension
$location

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 1330
abstract protected forceRewriteImage($fileContents, $location)

Parameters

$fileContents
$location

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

Parameters

$fileContents
$location

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

at line 1456
__destruct()

at line 1461
unloadImage()

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

at line 1483
fileIsAnimatedGif($filename)

Parameters

$filename

at line 1499
protected is_animated_gif($filename)

Parameters

$filename

at line 1595
fileContentIsAnimatedGif($filecontent)

Parameters

$filecontent