PHP Class JBZoo\Image\Image

Mostra file Open project: JBZoo/Image Class Usage Examples

Protected Properties

Property Type Description
$_exif array
$_filename string
$_height integer
$_image mixed GD Resource
$_mime string
$_orient string
$_quality integer
$_width integer

Public Methods

Method Description
__construct ( string | null $filename = null, boolean | null $strict = false ) Constructor
__destruct ( ) Destroy image resource
addFilter ( string | callable $filter ) Add filter to current image
autoOrient ( ) Rotates and/or flips an image automatically so the orientation will be correct (based on exif 'Orientation')
bestFit ( integer $maxWidth, integer $maxHeight ) Best fit (proportionally resize to fit in specified width/height) Shrink the image proportionally to fit inside a $width x $height box
cleanup ( ) Clean whole image object
create ( integer $width, integer | null $height = null, null | string $color = null ) Create an image from scratch
crop ( integer $left, integer $top, integer $right, integer $bottom ) Crop an image
fitToHeight ( integer $height ) Fit to height (proportionally resize to specified height)
fitToWidth ( integer $width ) Fit to width (proportionally resize to specified width)
getBase64 ( null | string $format = 'gif', integer | null $quality = null, $addMime = true ) : string Outputs image as data base64 to use as img src
getBinary ( null | string $format = null, integer | null $quality = null ) : string Outputs image as binary data
getHeight ( ) : integer Get the current height
getImage ( ) : mixed Get the current image resource
getInfo ( ) : array
getPath ( ) : string Get relative path to image
getUrl ( ) : string Get full URL to image (if not CLI mode)
getWidth ( ) : integer Get the current width
isGif ( ) : boolean
isJpeg ( ) : boolean
isLandscape ( ) : boolean
isPng ( ) : boolean
isPortrait ( ) : boolean
isSquare ( ) : boolean
loadFile ( string $filename ) Load an image
loadResource ( mixed $imageRes ) Load image resource
loadString ( string $imageString, boolean | null $strict = false ) Load an image
overlay ( string | Image $overlay, string $position = 'bottom right', float | integer $opacity = 0.4, integer $globOffsetX, integer $globOffsetY ) Overlay an image on top of another, works with 24-bit PNG alpha-transparency
resize ( integer $width, integer $height ) Resize an image to the specified dimensions
save ( null | integer $quality = null ) Save an image The resulting format will be determined by the file extension.
saveAs ( string $filename, null | integer $quality = null ) Save an image The resulting format will be determined by the file extension.
setQuality ( integer $newQuality )
thumbnail ( integer $width, integer | null $height = null, boolean $topIsZero = false ) Thumbnail.

Protected Methods

Method Description
_destroyImage ( ) Destroy image resource if not empty
_getExif ( ) : array
_getOrientation ( ) : string Get the current orientation
_imageCreate ( string $format ) : resource Create image resource
_loadMeta ( null | string $image = null, boolean | null $strict = false ) Get meta data of image or base64 string
_renderBinary ( string $format, integer $quality ) : array
_renderImageByFormat ( string $format, string $filename, integer $quality ) : boolean | string Render image resource as binary
_replaceImage ( $newImage )
_save ( string $filename, integer $quality ) : boolean Save image to file
_saveGif ( string $filename ) : boolean
_saveJpeg ( string $filename, integer $quality ) : boolean
_savePng ( string $filename, integer $quality ) : boolean

Method Details

__construct() public method

Constructor
public __construct ( string | null $filename = null, boolean | null $strict = false )
$filename string | null
$strict boolean | null

__destruct() public method

Destroy image resource
public __destruct ( )

_destroyImage() protected method

Destroy image resource if not empty
protected _destroyImage ( )

_getExif() protected method

protected _getExif ( ) : array
return array

_getOrientation() protected method

Get the current orientation
protected _getOrientation ( ) : string
return string portrait|landscape|square

_imageCreate() protected method

Create image resource
protected _imageCreate ( string $format ) : resource
$format string
return resource

_loadMeta() protected method

Get meta data of image or base64 string
protected _loadMeta ( null | string $image = null, boolean | null $strict = false )
$image null | string
$strict boolean | null

_renderBinary() protected method

protected _renderBinary ( string $format, integer $quality ) : array
$format string
$quality integer
return array

_renderImageByFormat() protected method

Render image resource as binary
protected _renderImageByFormat ( string $format, string $filename, integer $quality ) : boolean | string
$format string
$filename string
$quality integer
return boolean | string

_replaceImage() protected method

protected _replaceImage ( $newImage )
$newImage

_save() protected method

Save image to file
protected _save ( string $filename, integer $quality ) : boolean
$filename string
$quality integer
return boolean

_saveGif() protected method

protected _saveGif ( string $filename ) : boolean
$filename string
return boolean

_saveJpeg() protected method

protected _saveJpeg ( string $filename, integer $quality ) : boolean
$filename string
$quality integer
return boolean

_savePng() protected method

protected _savePng ( string $filename, integer $quality ) : boolean
$filename string
$quality integer
return boolean

addFilter() public method

Add filter to current image
public addFilter ( string | callable $filter )
$filter string | callable

autoOrient() public method

Rotates and/or flips an image automatically so the orientation will be correct (based on exif 'Orientation')
public autoOrient ( )

bestFit() public method

Best fit (proportionally resize to fit in specified width/height) Shrink the image proportionally to fit inside a $width x $height box
public bestFit ( integer $maxWidth, integer $maxHeight )
$maxWidth integer
$maxHeight integer

cleanup() public method

Clean whole image object
public cleanup ( )

create() public method

Create an image from scratch
public create ( integer $width, integer | null $height = null, null | string $color = null )
$width integer Image width
$height integer | null If omitted - assumed equal to $width
$color null | string Hex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127

crop() public method

Crop an image
public crop ( integer $left, integer $top, integer $right, integer $bottom )
$left integer Left
$top integer Top
$right integer Right
$bottom integer Bottom

fitToHeight() public method

Fit to height (proportionally resize to specified height)
public fitToHeight ( integer $height )
$height integer

fitToWidth() public method

Fit to width (proportionally resize to specified width)
public fitToWidth ( integer $width )
$width integer

getBase64() public method

Outputs image as data base64 to use as img src
public getBase64 ( null | string $format = 'gif', integer | null $quality = null, $addMime = true ) : string
$format null | string If omitted or null - format of original file will be used, may be gif|jpg|png
$quality integer | null Output image quality in percents 0-100
return string

getBinary() public method

Outputs image as binary data
public getBinary ( null | string $format = null, integer | null $quality = null ) : string
$format null | string If omitted or null - format of original file will be used, may be gif|jpg|png
$quality integer | null Output image quality in percents 0-100
return string

getHeight() public method

Get the current height
public getHeight ( ) : integer
return integer

getImage() public method

Get the current image resource
public getImage ( ) : mixed
return mixed

getInfo() public method

public getInfo ( ) : array
return array

getPath() public method

Get relative path to image
public getPath ( ) : string
return string

getUrl() public method

Get full URL to image (if not CLI mode)
public getUrl ( ) : string
return string

getWidth() public method

Get the current width
public getWidth ( ) : integer
return integer

isGif() public method

public isGif ( ) : boolean
return boolean

isJpeg() public method

public isJpeg ( ) : boolean
return boolean

isLandscape() public method

public isLandscape ( ) : boolean
return boolean

isPng() public method

public isPng ( ) : boolean
return boolean

isPortrait() public method

public isPortrait ( ) : boolean
return boolean

isSquare() public method

public isSquare ( ) : boolean
return boolean

loadFile() public method

Load an image
public loadFile ( string $filename )
$filename string Path to image file

loadResource() public method

Load image resource
public loadResource ( mixed $imageRes )
$imageRes mixed Image GD Resource

loadString() public method

Load an image
public loadString ( string $imageString, boolean | null $strict = false )
$imageString string Binary images
$strict boolean | null

overlay() public method

Overlay an image on top of another, works with 24-bit PNG alpha-transparency
public overlay ( string | Image $overlay, string $position = 'bottom right', float | integer $opacity = 0.4, integer $globOffsetX, integer $globOffsetY )
$overlay string | Image An image filename or a Image object
$position string center|top|left|bottom|right|top left|top right|bottom left|bottom right
$opacity float | integer Overlay opacity 0-1 or 0-100
$globOffsetX integer Horizontal offset in pixels
$globOffsetY integer Vertical offset in pixels

resize() public method

Resize an image to the specified dimensions
public resize ( integer $width, integer $height )
$width integer
$height integer

save() public method

Save an image The resulting format will be determined by the file extension.
public save ( null | integer $quality = null )
$quality null | integer Output image quality in percents 0-100

saveAs() public method

Save an image The resulting format will be determined by the file extension.
public saveAs ( string $filename, null | integer $quality = null )
$filename string If omitted - original file will be overwritten
$quality null | integer Output image quality in percents 0-100

setQuality() public method

public setQuality ( integer $newQuality )
$newQuality integer

thumbnail() public method

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. Useful for generating thumbnails.
public thumbnail ( integer $width, integer | null $height = null, boolean $topIsZero = false )
$width integer
$height integer | null If omitted - assumed equal to $width
$topIsZero boolean Force top offset = 0

Property Details

$_exif protected_oe property

protected array $_exif
return array

$_filename protected_oe property

protected string $_filename
return string

$_height protected_oe property

protected int $_height
return integer

$_image protected_oe property

GD Resource
protected mixed $_image
return mixed

$_mime protected_oe property

protected string $_mime
return string

$_orient protected_oe property

protected string $_orient
return string

$_quality protected_oe property

protected int $_quality
return integer

$_width protected_oe property

protected int $_width
return integer