PHP Класс JBZoo\Image\Image

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_exif array
$_filename string
$_height integer
$_image mixed GD Resource
$_mime string
$_orient string
$_quality integer
$_width integer

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
_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

Описание методов

__construct() публичный Метод

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

__destruct() публичный Метод

Destroy image resource
public __destruct ( )

_destroyImage() защищенный Метод

Destroy image resource if not empty
protected _destroyImage ( )

_getExif() защищенный Метод

protected _getExif ( ) : array
Результат array

_getOrientation() защищенный Метод

Get the current orientation
protected _getOrientation ( ) : string
Результат string portrait|landscape|square

_imageCreate() защищенный Метод

Create image resource
protected _imageCreate ( string $format ) : resource
$format string
Результат resource

_loadMeta() защищенный Метод

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 _renderBinary ( string $format, integer $quality ) : array
$format string
$quality integer
Результат array

_renderImageByFormat() защищенный Метод

Render image resource as binary
protected _renderImageByFormat ( string $format, string $filename, integer $quality ) : boolean | string
$format string
$filename string
$quality integer
Результат boolean | string

_replaceImage() защищенный Метод

protected _replaceImage ( $newImage )
$newImage

_save() защищенный Метод

Save image to file
protected _save ( string $filename, integer $quality ) : boolean
$filename string
$quality integer
Результат boolean

_saveGif() защищенный Метод

protected _saveGif ( string $filename ) : boolean
$filename string
Результат boolean

_saveJpeg() защищенный Метод

protected _saveJpeg ( string $filename, integer $quality ) : boolean
$filename string
$quality integer
Результат boolean

_savePng() защищенный Метод

protected _savePng ( string $filename, integer $quality ) : boolean
$filename string
$quality integer
Результат boolean

addFilter() публичный Метод

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

autoOrient() публичный Метод

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

bestFit() публичный Метод

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() публичный Метод

Clean whole image object
public cleanup ( )

create() публичный Метод

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() публичный Метод

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() публичный Метод

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

fitToWidth() публичный Метод

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

getBase64() публичный Метод

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
Результат string

getBinary() публичный Метод

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
Результат string

getHeight() публичный Метод

Get the current height
public getHeight ( ) : integer
Результат integer

getImage() публичный Метод

Get the current image resource
public getImage ( ) : mixed
Результат mixed

getInfo() публичный Метод

public getInfo ( ) : array
Результат array

getPath() публичный Метод

Get relative path to image
public getPath ( ) : string
Результат string

getUrl() публичный Метод

Get full URL to image (if not CLI mode)
public getUrl ( ) : string
Результат string

getWidth() публичный Метод

Get the current width
public getWidth ( ) : integer
Результат integer

isGif() публичный Метод

public isGif ( ) : boolean
Результат boolean

isJpeg() публичный Метод

public isJpeg ( ) : boolean
Результат boolean

isLandscape() публичный Метод

public isLandscape ( ) : boolean
Результат boolean

isPng() публичный Метод

public isPng ( ) : boolean
Результат boolean

isPortrait() публичный Метод

public isPortrait ( ) : boolean
Результат boolean

isSquare() публичный Метод

public isSquare ( ) : boolean
Результат boolean

loadFile() публичный Метод

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

loadResource() публичный Метод

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

loadString() публичный Метод

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

overlay() публичный Метод

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() публичный Метод

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

save() публичный Метод

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() публичный Метод

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 setQuality ( integer $newQuality )
$newQuality integer

thumbnail() публичный Метод

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

Описание свойств

$_exif защищенное свойство

protected array $_exif
Результат array

$_filename защищенное свойство

protected string $_filename
Результат string

$_height защищенное свойство

protected int $_height
Результат integer

$_image защищенное свойство

GD Resource
protected mixed $_image
Результат mixed

$_mime защищенное свойство

protected string $_mime
Результат string

$_orient защищенное свойство

protected string $_orient
Результат string

$_quality защищенное свойство

protected int $_quality
Результат integer

$_width защищенное свойство

protected int $_width
Результат integer