PHP Class JBZoo\Image\Image

Afficher le fichier Open project: JBZoo/Image Class Usage Examples

Protected Properties

Свойство Type Description
$_exif array
$_filename string
$_height integer
$_image mixed GD Resource
$_mime string
$_orient string
$_quality integer
$_width integer

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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

__destruct() public méthode

Destroy image resource
public __destruct ( )

_destroyImage() protected méthode

Destroy image resource if not empty
protected _destroyImage ( )

_getExif() protected méthode

protected _getExif ( ) : array
Résultat array

_getOrientation() protected méthode

Get the current orientation
protected _getOrientation ( ) : string
Résultat string portrait|landscape|square

_imageCreate() protected méthode

Create image resource
protected _imageCreate ( string $format ) : resource
$format string
Résultat resource

_loadMeta() protected méthode

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 méthode

protected _renderBinary ( string $format, integer $quality ) : array
$format string
$quality integer
Résultat array

_renderImageByFormat() protected méthode

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

_replaceImage() protected méthode

protected _replaceImage ( $newImage )
$newImage

_save() protected méthode

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

_saveGif() protected méthode

protected _saveGif ( string $filename ) : boolean
$filename string
Résultat boolean

_saveJpeg() protected méthode

protected _saveJpeg ( string $filename, integer $quality ) : boolean
$filename string
$quality integer
Résultat boolean

_savePng() protected méthode

protected _savePng ( string $filename, integer $quality ) : boolean
$filename string
$quality integer
Résultat boolean

addFilter() public méthode

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

autoOrient() public méthode

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

bestFit() public méthode

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 méthode

Clean whole image object
public cleanup ( )

create() public méthode

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 méthode

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 méthode

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

fitToWidth() public méthode

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

getBase64() public méthode

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
Résultat string

getBinary() public méthode

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
Résultat string

getHeight() public méthode

Get the current height
public getHeight ( ) : integer
Résultat integer

getImage() public méthode

Get the current image resource
public getImage ( ) : mixed
Résultat mixed

getInfo() public méthode

public getInfo ( ) : array
Résultat array

getPath() public méthode

Get relative path to image
public getPath ( ) : string
Résultat string

getUrl() public méthode

Get full URL to image (if not CLI mode)
public getUrl ( ) : string
Résultat string

getWidth() public méthode

Get the current width
public getWidth ( ) : integer
Résultat integer

isGif() public méthode

public isGif ( ) : boolean
Résultat boolean

isJpeg() public méthode

public isJpeg ( ) : boolean
Résultat boolean

isLandscape() public méthode

public isLandscape ( ) : boolean
Résultat boolean

isPng() public méthode

public isPng ( ) : boolean
Résultat boolean

isPortrait() public méthode

public isPortrait ( ) : boolean
Résultat boolean

isSquare() public méthode

public isSquare ( ) : boolean
Résultat boolean

loadFile() public méthode

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

loadResource() public méthode

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

loadString() public méthode

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

overlay() public méthode

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 méthode

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

save() public méthode

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 méthode

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 méthode

public setQuality ( integer $newQuality )
$newQuality integer

thumbnail() public méthode

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
Résultat array

$_filename protected_oe property

protected string $_filename
Résultat string

$_height protected_oe property

protected int $_height
Résultat integer

$_image protected_oe property

GD Resource
protected mixed $_image
Résultat mixed

$_mime protected_oe property

protected string $_mime
Résultat string

$_orient protected_oe property

protected string $_orient
Résultat string

$_quality protected_oe property

protected int $_quality
Résultat integer

$_width protected_oe property

protected int $_width
Résultat integer