class vB_Image_ImageMagick extends vB_Image

Image class for ImageMagick

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
string $convertpath
string $identifypath
integer $returnvalue
string $identifyformat
protected string $version Version of Imagemagick /convert
string $convertoptions
string $error
protected $thumbcolor
array $thumb_types

Methods

__sleep()

No description

__wakeup()

No description

void
__construct($options)

Constructor Sets ImageMagick paths to convert and identify

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

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)

See function definition in vB_Image

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

from vB_Image
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.

fileIsAnimatedGif($filename)

No description

from vB_Image
is_animated_gif($filename)

No description

from vB_Image
fileContentIsAnimatedGif($filecontent)

No description

from vB_Image
mixed
fetchImExec($command, $args, $needoutput = false, $dieongs = true)

Generic call to imagemagick binaries

mixed
fetchVersion()

Fetch Imagemagick Version

mixed
fetchIdentifyInfo(string $filename)

Identify an image

void
setConvertOptions($width = 100, $height = 100, $quality = 75, $labelimage = false, $drawborder = false, $jpegconvert = false, $owidth = null, $oheight = null, $ofilesize = null, $do_orient = false, $do_strip = false)

Private Set image size for convert

mixed
fetchConvertedImage(string $filename, string $output, array $imageinfo, boolean $thumbnail = true, boolean $sharpen = true)

Convert an image

string
annotate($letter, $font, $slant = false, $random = true)

Return a letter position command

Details

in vB_Trait_NoSerialize at line 15
__sleep()

in vB_Trait_NoSerialize at line 20
__wakeup()

at line 87
void __construct($options)

Constructor Sets ImageMagick paths to convert and identify

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 860
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

at line 906
fetchImageInfoForThumbnails($filename)

Parameters

$filename

at line 1152
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 953
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)

See function definition in vB_Image

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

Parameters

$fileContents
$location

in vB_Image at line 1332
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()

at line 279
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 173
protected mixed fetchImExec($command, $args, $needoutput = false, $dieongs = true)

Generic call to imagemagick binaries

Parameters

$command
$args
$needoutput
$dieongs

Return Value

mixed

at line 358
protected mixed fetchVersion()

Fetch Imagemagick Version

Return Value

mixed

at line 384
protected mixed fetchIdentifyInfo(string $filename)

Identify an image

Parameters

string $filename File to obtain image information from

Return Value

mixed

at line 488
protected void setConvertOptions($width = 100, $height = 100, $quality = 75, $labelimage = false, $drawborder = false, $jpegconvert = false, $owidth = null, $oheight = null, $ofilesize = null, $do_orient = false, $do_strip = false)

Private Set image size for convert

Parameters

$width
$height
$quality
$labelimage
$drawborder
$jpegconvert
$owidth
$oheight
$ofilesize
$do_orient
$do_strip

Return Value

void

at line 570
protected mixed fetchConvertedImage(string $filename, string $output, array $imageinfo, boolean $thumbnail = true, boolean $sharpen = true)

Convert an image

Parameters

string $filename Image file to convert
string $output Filename to write converted image to
array $imageinfo Array of information about the image, typically the result of fetchImageInfo($filename)
boolean $thumbnail Generate a thumbnail for display in a browser
boolean $sharpen Sharpen the output

Return Value

mixed

at line 1313
protected string annotate($letter, $font, $slant = false, $random = true)

Return a letter position command

Parameters

$letter
$font
$slant
$random

Return Value

string