\OCPIImage

Class for basic image manipulation

Summary

Methods
Constants
valid()
mimeType()
width()
height()
widthTopLeft()
heightTopLeft()
show()
save()
resource()
data()
getOrientation()
fixOrientation()
resize()
preciseResize()
centerCrop()
crop()
fitIn()
scaleDownToFit()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

valid()

valid() : boolean

Determine whether the object contains an image resource.

Returns

boolean

mimeType()

mimeType() : string

Returns the MIME type of the image or an empty string if no image is loaded.

Returns

string

width()

width() : integer

Returns the width of the image or -1 if no image is loaded.

Returns

integer

height()

height() : integer

Returns the height of the image or -1 if no image is loaded.

Returns

integer

widthTopLeft()

widthTopLeft() : integer

Returns the width when the image orientation is top-left.

Returns

integer

heightTopLeft()

heightTopLeft() : integer

Returns the height when the image orientation is top-left.

Returns

integer

show()

show(string  $mimeType = null) : boolean

Outputs the image.

Parameters

string $mimeType

Returns

boolean

save()

save(string  $filePath = null, string  $mimeType = null) : boolean

Saves the image.

Parameters

string $filePath
string $mimeType

Returns

boolean

resource()

resource() : resource

Returns

resource —

Returns the image resource in any.

data()

data() : string

Returns

string —

Returns the raw image data.

getOrientation()

getOrientation() : integer

(I'm open for suggestions on better method name ;) Get the orientation based on EXIF data.

Returns

integer —

The orientation or -1 if no EXIF data is available.

fixOrientation()

fixOrientation() : boolean

(I'm open for suggestions on better method name ;) Fixes orientation based on EXIF data.

Returns

boolean

resize()

resize(integer  $maxSize) : boolean

Resizes the image preserving ratio.

Parameters

integer $maxSize

The maximum size of either the width or height.

Returns

boolean

preciseResize()

preciseResize(integer  $width, integer  $height) : boolean

Parameters

integer $width
integer $height

Returns

boolean

centerCrop()

centerCrop(integer  $size) : boolean

Crops the image to the middle square. If the image is already square it just returns.

Parameters

integer $size

maximum size for the result (optional)

Returns

boolean —

for success or failure

crop()

crop(integer  $x, integer  $y, integer  $w, integer  $h) : boolean

Crops the image from point $x$y with dimension $wx$h.

Parameters

integer $x

Horizontal position

integer $y

Vertical position

integer $w

Width

integer $h

Height

Returns

boolean —

for success or failure

fitIn()

fitIn(integer  $maxWidth, integer  $maxHeight) : boolean

Resizes the image to fit within a boundary while preserving ratio.

Parameters

integer $maxWidth
integer $maxHeight

Returns

boolean

scaleDownToFit()

scaleDownToFit(integer  $maxWidth, integer  $maxHeight) : boolean

Shrinks the image to fit within a boundary while preserving ratio.

Parameters

integer $maxWidth
integer $maxHeight

Returns

boolean