Image
Class to manipulate an image.
since |
1.7.3 |
---|---|
package |
Joomla CMS |
Methods
__construct
Class constructor.
__construct( source = null) :
since |
1.7.3 |
---|---|
throws |
|
Arguments
- source
mixed
Either a file path for a source image or a GD resource handler for an image.
Response
mixed
__destruct
Method to call the destroy() method one last time to free any memory when the object is unset
__destruct() :
createThumbnails
Method to create thumbnails from the current image and save them to disk. It allows creation by resizing or cropping the original image.
createThumbnails( thumbSizes, creationMethod = self::SCALE_INSIDE, thumbsFolder = null, useOriginalName = false) : mixed||string|int
since |
4.3.0 |
---|---|
throws |
|
Arguments
- thumbSizes
mixed
string or array of strings. Example: $thumbSizes = ['150x75','250x150'];- creationMethod
int
1-3 resize $scaleMethod | 4 create cropping- thumbsFolder
string
destination thumbs folder. null generates a thumbs folder in the image folder- useOriginalName
bool
Shall we use the original image name? Defaults is false, {filename}_{width}x{height}.{ext}
Response
array<string|int, mixed>
createThumbs
Method to create thumbnails from the current image and save them to disk. It allows creation by resizing or cropping the original image.
createThumbs( thumbSizes, creationMethod = self::SCALE_INSIDE, thumbsFolder = null) : mixed||string|int
since |
2.5.0 |
---|---|
throws |
|
deprecated |
4.0 will be removed in 6.0 Use \Joomla\CMS\Image\createThumbnails instead |
Arguments
- thumbSizes
mixed
string or array of strings. Example: $thumbSizes = ['150x75','250x150'];- creationMethod
int
1-3 resize $scaleMethod | 4 create cropping- thumbsFolder
string
destination thumbs folder. null generates a thumbs folder in the image folder
Response
array<string|int, mixed>
crop
Method to crop the current image.
crop( width, height, left = null, top = null, createNew = true) : \Joomla\CMS\Image\Image
since |
2.5.0 |
---|---|
throws |
|
Arguments
- width
mixed
The width of the image section to crop in pixels or a percentage.- height
mixed
The height of the image section to crop in pixels or a percentage.- left
int
The number of pixels from the left to start cropping.- top
int
The number of pixels from the top to start cropping.- createNew
bool
If true the current image will be cloned, cropped and returned; else the current image will be cropped and returned.
Response
cropResize
Method to crop an image after resizing it to maintain proportions without having to do all the set up work.
cropResize( width, height, createNew = true) : \Joomla\CMS\Image\Image
since |
2.5.0 |
---|
Arguments
- width
int
The desired width of the image in pixels or a percentage.- height
int
The desired height of the image in pixels or a percentage.- createNew
bool
If true the current image will be cloned, resized, cropped and returned.
Response
destroy
Method to destroy an image handle and free the memory associated with the handle
destroy() :
since |
2.5.0 |
---|
Response
bool
True on success, false on failure or if no image is loaded
filter
Method to apply a filter to the image by type. Two examples are: grayscale and sketchy.
filter( type, mixed||string|int options = []) : \Joomla\CMS\Image\Image
since |
2.5.0 |
---|---|
see | Filter |
throws |
|
Arguments
- type
string
The name of the image filter to apply.- options
array<string|int, mixed>
An array of options for the filter.
Response
flip
Method to flip the current image.
flip( mode, createNew = true) : \Joomla\CMS\Image\Image
since |
3.4.2 |
---|---|
throws |
|
Arguments
- mode
int
The flip mode for flipping the image {@link http://php.net/imageflip#refsect1-function.imageflip-parameters}- createNew
bool
If true the current image will be cloned, flipped and returned; else the current image will be flipped and returned.
Response
generateThumbs
Method to generate thumbnails from the current image. It allows creation by resizing or cropping the original image.
generateThumbs( thumbSizes, creationMethod = self::SCALE_INSIDE) : mixed||string|int
since |
2.5.0 |
---|---|
throws |
|
Arguments
- thumbSizes
mixed
String or array of strings. Example: $thumbSizes = array('150x75','250x150');- creationMethod
int
1-3 resize $scaleMethod | 4 create cropping | 5 resize then crop
Response
array<string|int, mixed>
getFilterInstance
Method to get an image filter instance of a specified type.
getFilterInstance( type) : \Joomla\CMS\Image\ImageFilter
since |
2.5.0 |
---|---|
throws |
|
Arguments
- type
string
The image filter type to get.
Response
getHandle
Get the image resource handle
getHandle() :
since |
3.8.0 |
---|---|
throws |
|
Response
resource
getHeight
Method to get the height of the image in pixels.
getHeight() :
since |
2.5.0 |
---|---|
throws |
|
Response
int
getImageFileProperties
Method to return a properties object for an image given a filesystem path.
getImageFileProperties( path) : \stdClass
The result object has values for image width, height, type, attributes, mime type, bits, and channels.
since |
2.5.0 |
---|---|
throws |
|
Arguments
- path
string
The filesystem path to the image for which to get properties.
Response
stdClass
getOrientation
Method to detect whether an image's orientation is landscape, portrait or square.
getOrientation() :
The orientation will be returned as a string.
since |
3.4.2 |
---|
Response
mixed
Orientation string or null.
getOrientationString
Compare width and height integers to determine image orientation.
getOrientationString( width, height) :
since |
3.4.2 |
---|
Arguments
- width
int
The width value to use for calculation- height
int
The height value to use for calculation
Response
string
Orientation string
getPath
Method to return the path
getPath() :
since |
2.5.0 |
---|
Response
string
getWidth
Method to get the width of the image in pixels.
getWidth() :
since |
2.5.0 |
---|---|
throws |
|
Response
int
isLoaded
Method to determine whether or not an image has been loaded into the object.
isLoaded() :
since |
2.5.0 |
---|
Response
bool
isTransparent
Method to determine whether or not the image has transparency.
isTransparent() :
since |
2.5.0 |
---|---|
throws |
|
Response
bool
loadFile
Method to load a file into the Image object as the resource.
loadFile( path) :
since |
2.5.0 |
---|---|
throws |
|
Arguments
- path
string
The filesystem path to load as an image.
Response
void
prepareDimensions
Method to get the new dimensions for a resized image.
prepareDimensions( width, height, scaleMethod) : \stdClass
since |
2.5.0 |
---|---|
throws |
|
Arguments
- width
int
The width of the resized image in pixels.- height
int
The height of the resized image in pixels.- scaleMethod
int
The method to use for scaling
Response
stdClass
resize
Method to resize the current image.
resize( width, height, createNew = true, scaleMethod = self::SCALE_INSIDE) : \Joomla\CMS\Image\Image
since |
2.5.0 |
---|---|
throws |
|
Arguments
- width
mixed
The width of the resized image in pixels or a percentage.- height
mixed
The height of the resized image in pixels or a percentage.- createNew
bool
If true the current image will be cloned, resized and returned; else the current image will be resized and returned.- scaleMethod
int
Which method to use for scaling
Response
rotate
Method to rotate the current image.
rotate( angle, background = -1, createNew = true) : \Joomla\CMS\Image\Image
since |
2.5.0 |
---|---|
throws |
|
Arguments
- angle
mixed
The angle of rotation for the image- background
int
The background color to use when areas are added due to rotation- createNew
bool
If true the current image will be cloned, rotated and returned; else the current image will be rotated and returned.
Response
sanitizeHeight
Method to sanitize a height value.
sanitizeHeight( height, width) :
since |
2.5.0 |
---|
Arguments
- height
mixed
The input height value to sanitize.- width
mixed
The input width value for reference.
Response
int
sanitizeOffset
Method to sanitize an offset value like left or top.
sanitizeOffset( offset) :
since |
2.5.0 |
---|
Arguments
- offset
mixed
An offset value.
Response
int
sanitizeWidth
Method to sanitize a width value.
sanitizeWidth( width, height) :
since |
2.5.0 |
---|
Arguments
- width
mixed
The input width value to sanitize.- height
mixed
The input height value for reference.
Response
int
setThumbnailGenerate
Method for set option of generate thumbnail method
setThumbnailGenerate( quality = true) :
since |
3.7.0 |
---|
Arguments
- quality
bool
True for best quality. False for best speed.
Response
void
toFile
Method to write the current image out to a file or output directly.
toFile( path, type = IMAGETYPE_JPEG, mixed||string|int options = []) :
link | |
---|---|
since |
2.5.0 |
throws |
|
Arguments
- path
mixed
The filesystem path to save the image. When null, the raw image stream will be outputted directly.- type
int
The image type to save the file as.- options
array<string|int, mixed>
The image type options to use in saving the file. For PNG and JPEG formats usequality
key to set compression level (0..9 and 0..100)
Response
bool
watermark
Watermark the image
watermark(\Joomla\CMS\Image\Image watermark, transparency = 50, bottomMargin, rightMargin) : \Joomla\CMS\Image\Image
Constants
SCALE_FILL
Value | 1 |
---|---|
const |
integer |
since |
2.5.0 |
SCALE_INSIDE
Value | 2 |
---|---|
const |
integer |
since |
2.5.0 |
SCALE_OUTSIDE
Value | 3 |
---|---|
const |
integer |
since |
2.5.0 |
CROP
Value | 4 |
---|---|
const |
integer |
since |
2.5.0 |
CROP_RESIZE
Value | 5 |
---|---|
const |
integer |
since |
2.5.0 |
SCALE_FIT
Value | 6 |
---|---|
const |
integer |
since |
2.5.0 |
ORIENTATION_LANDSCAPE
Value | 'landscape' |
---|---|
const |
string |
since |
3.4.2 |
ORIENTATION_PORTRAIT
Value | 'portrait' |
---|---|
const |
string |
since |
3.4.2 |
ORIENTATION_SQUARE
Value | 'square' |
---|---|
const |
string |
since |
3.4.2 |
Properties
handle
The image resource handle.
since |
2.5.0 |
---|
Type(s)
resource
path
The source image path.
since |
2.5.0 |
---|
Type(s)
string
formats
Whether or not different image formats are supported.
since |
2.5.0 |
---|
Type(s)
array<string|int, mixed>
generateBestQuality
Flag if an image should use the best quality available. Disable for improved performance.
since |
3.7.0 |
---|
Type(s)
bool