Canvas
extends Image
in package
A Canvas represents a rectangular image area on which one can append images, text and figures.
Tags
Table of Contents
- $boxHeight : int
- $boxWidth : int
- $boxX : int
- $boxY : int
- $elementList : array<string|int, mixed>
- $extension : string
- $filename : string
- $from : string
- $height : int
- $mimetype : string
- $name : string
- $opacity : int
- $preserve : bool
- $quality : int
- $resource|\GdImage : resource
- $type : int
- $width : int
- $x : int
- $y : int
- $boxHeight : mixed
- $boxWidth : mixed
- $boxX : mixed
- $boxY : mixed
- $extension : mixed
- $filename : mixed
- $from : mixed
- $height : mixed
- $mimetype : mixed
- $name : mixed
- $opacity : mixed
- $preserve : mixed
- $quality : mixed
- $resource : mixed
- $type : mixed
- $width : mixed
- $x : mixed
- $y : mixed
- $elementList : array<string|int, mixed>
- List of elements.
- __construct() : mixed
- Constructs a new Canvas.
- append() : Canvas|static
- Adds one or more elements to canvas.
- centerCrop() : Image|static
- Cuts the image proportionally and centered.
- crop() : Image|static
- Cuts part of image.
- destroy() : Image|static
- Destroys the current resource.
- draw() : Canvas|static
- Draws the canvas.
- from() : Image|static
- Loads an image from Image or Figure class.
- getBoxHeight() : int
- Gets box height.
- getBoxLeft() : int
- Gets box left position.
- getBoxTop() : int
- Gets box top position.
- getBoxWidth() : int
- Gets box width.
- getExtension() : string
- Gets extension (jpg, png or gif).
- getFilename() : string
- Gets filename path of the image.
- getHeight() : int
- Gets height.
- getLeft() : int
- Gets left position.
- getLoadedFrom() : string
- Gets where the image was loaded: 'local' or 'external'.
- getName() : string
- Gets the image file name.
- getOpacity() : int
- Gets opacity.
- getPropHeight() : int
- Gets proportional height of image from width value.
- getPropWidth() : int
- Gets proportional width of image from height value.
- getQuality() : int
- Gets quality.
- getResource() : resource|GdImage
- Gets the resource or `\GdImage` object (PHP 8.0+) of the image.
- getTop() : int
- Gets top position.
- getType() : int
- Gets the image type code (IMAGETYPE_JPEG, IMAGETYPE_PNG or IMAGETYPE_GIF).
- getWidth() : int
- Gets width.
- isExternal() : bool
- Checks if image was loaded from external url.
- isGIF() : bool
- Checks if image is a GIF.
- isImageGdImage() : bool
- Checks if image was loaded from a `\GdImage` object (PHP 8.0+).
- isImageResource() : bool
- Checks if image was loaded from an image resource (PHP 7.4).
- isImageString() : bool
- Checks if image was loaded from image string.
- isJPG() : bool
- Checks if image is a JPG.
- isLocal() : bool
- Checks if image was loaded from local path.
- isPNG() : bool
- Checks if image is a PNG.
- load() : Image|static
- Loads an image from a local path, external url or image string.
- output() : Image|static
- Outputs the image on browser.
- preserve() : Image|static
- Preserves the resource image when save or output function is called.
- render() : resource
- Render the image in-memory and return the resource.
- resizeToHeight() : Image|static
- Resize image proportionally basing on the height of the image.
- resizeToWidth() : Image|static
- Resize image proportionally basing on the width of the image.
- rotate() : Image|static
- Rotate the image with a given angle.
- save() : Image|static
- Saves the image to specific path.
- scale() : Image|static
- Scales the image.
- setBoxHeight() : Image|static
- Sets height of box image.
- setBoxLeft() : Image|static
- Sets left position of box image.
- setBoxTop() : Image|static
- Sets top position of box image.
- setBoxWidth() : Image|static
- Sets width of box image.
- setLeft() : Image|static
- Sets left position of image.
- setOpacity() : Image|static
- Sets opacity.
- setQuality() : Image|static
- Sets quality for image.
- setResource() : Image|static
- Sets image resource.
- setTop() : Image|static
- Sets top position of image.
- toGIF() : Image|static
- Changes output format to GIF.
- toJPG() : Image|static
- Changes output format to JPG.
- toPNG() : Image|static
- Changes output format to PNG.
- addOpacityFilter() : void
- Add opacity filter to the current resource.
- drawImage() : void
- Draw the an Image or Figure element.
- drawText() : void
- Draw a Text element.
- fetchImageContentFromURL() : string
- Fetch an image string content from URL.
- isImageStringByString() : bool
- Checks if string is Image string.
- loadImageFromFile() : void
- Load an image file from path.
- loadImageFromResource() : void
- Load an image from a resource or `\GdImage`.
- loadImageFromString() : void
- Load an image from image string.
- loadImageFromURL() : void
- Load an image from URL.
- outputBuffer() : Image|static
- Output the image to either the browser or a file.
- outputBufferByImage() : mixed
- resize() : Image|static
- Resizes the image.
Properties
$boxHeight
public
int
$boxHeight
$boxWidth
public
int
$boxWidth
$boxX
public
int
$boxX
$boxY
public
int
$boxY
$elementList
public
array<string|int, mixed>
$elementList
An array of elements (Image, Figure or Text classes).
$extension
public
string
$extension
Default 'jpg'
$filename
public
string
$filename
$from
public
string
$from
Default 'local'
$height
public
int
$height
$mimetype
public
string
$mimetype
Default 'image/jpeg'
$name
public
string
$name
$opacity
public
int
$opacity
From 0 to 1
$preserve
public
bool
$preserve
Default FALSE
$quality
public
int
$quality
$resource|\GdImage
public
resource
$resource|\GdImage
$type
public
int
$type
IMAGETYPE_JPEG
$width
public
int
$width
$x
public
int
$x
$y
public
int
$y
$boxHeight
protected
mixed
$boxHeight
= 0
Tags
$boxWidth
protected
mixed
$boxWidth
= 0
Tags
$boxX
protected
mixed
$boxX
= 0
Tags
$boxY
protected
mixed
$boxY
= 0
Tags
$extension
protected
mixed
$extension
= 'jpg'
Tags
$filename
protected
mixed
$filename
Tags
$from
protected
mixed
$from
= 'local'
Tags
$height
protected
mixed
$height
= 0
Tags
$mimetype
protected
mixed
$mimetype
= 'image/jpeg'
Tags
$name
protected
mixed
$name
Tags
$opacity
protected
mixed
$opacity
= 1
Tags
$preserve
protected
mixed
$preserve
= false
Tags
$quality
protected
mixed
$quality
= 100
Tags
$resource
protected
mixed
$resource
Tags
$type
protected
mixed
$type
= IMAGETYPE_JPEG
Tags
$width
protected
mixed
$width
= 0
Tags
$x
protected
mixed
$x
= 0
Tags
$y
protected
mixed
$y
= 0
Tags
$elementList
List of elements.
private
array<string|int, mixed>
$elementList
= []
Tags
Methods
__construct()
Constructs a new Canvas.
public
__construct([mixed $element = null ]) : mixed
Parameters
- $element : mixed = null
-
only Image or Figure classes
Tags
Return values
mixed —append()
Adds one or more elements to canvas.
public
append(mixed $elements) : Canvas|static
Parameters
- $elements : mixed
-
single or array of Image, Figure, Text classes
Tags
Return values
Canvas|static —centerCrop()
Cuts the image proportionally and centered.
public
centerCrop(int $width, int $height) : Image|static
Parameters
- $width : int
-
width crop
- $height : int
-
height crop
Tags
Return values
Image|static —crop()
Cuts part of image.
public
crop(int $width, int $height[, int $x1 = 0 ][, int $y1 = 0 ][, int $dstX = 0 ][, int $dstY = 0 ]) : Image|static
Parameters
- $width : int
-
width crop
- $height : int
-
height crop
- $x1 : int = 0
-
[Optional] x-coordinate of source point
- $y1 : int = 0
-
[Optional] y-coordinate of source point
- $dstX : int = 0
-
[Optional] x-coordinate of destination point
- $dstY : int = 0
-
[Optional] y-coordinate of destination point
Tags
Return values
Image|static —destroy()
Destroys the current resource.
public
destroy() : Image|static
Tags
Return values
Image|static —draw()
Draws the canvas.
public
draw() : Canvas|static
Tags
Return values
Canvas|static —from()
Loads an image from Image or Figure class.
public
from([Image $element = null ]) : Image|static
Parameters
- $element : Image = null
-
image or Figure class
Return values
Image|static —getBoxHeight()
Gets box height.
public
getBoxHeight() : int
Tags
Return values
int —getBoxLeft()
Gets box left position.
public
getBoxLeft() : int
Tags
Return values
int —getBoxTop()
Gets box top position.
public
getBoxTop() : int
Tags
Return values
int —getBoxWidth()
Gets box width.
public
getBoxWidth() : int
Tags
Return values
int —getExtension()
Gets extension (jpg, png or gif).
public
getExtension() : string
Tags
Return values
string —getFilename()
Gets filename path of the image.
public
getFilename() : string
Tags
Return values
string —getHeight()
Gets height.
public
getHeight() : int
Tags
Return values
int —getLeft()
Gets left position.
public
getLeft() : int
Tags
Return values
int —getLoadedFrom()
Gets where the image was loaded: 'local' or 'external'.
public
getLoadedFrom() : string
Tags
Return values
string —getName()
Gets the image file name.
public
getName() : string
Tags
Return values
string —getOpacity()
Gets opacity.
public
getOpacity() : int
Tags
Return values
int —getPropHeight()
Gets proportional height of image from width value.
public
getPropHeight(int $width) : int
Parameters
- $width : int
Tags
Return values
int —getPropWidth()
Gets proportional width of image from height value.
public
getPropWidth(int $height) : int
Parameters
- $height : int
Tags
Return values
int —getQuality()
Gets quality.
public
getQuality() : int
Tags
Return values
int —getResource()
Gets the resource or `\GdImage` object (PHP 8.0+) of the image.
public
getResource() : resource|GdImage
Tags
Return values
resource|GdImage —getTop()
Gets top position.
public
getTop() : int
Tags
Return values
int —getType()
Gets the image type code (IMAGETYPE_JPEG, IMAGETYPE_PNG or IMAGETYPE_GIF).
public
getType() : int
Tags
Return values
int —getWidth()
Gets width.
public
getWidth() : int
Tags
Return values
int —isExternal()
Checks if image was loaded from external url.
public
isExternal() : bool
Tags
Return values
bool —isGIF()
Checks if image is a GIF.
public
isGIF() : bool
Tags
Return values
bool —isImageGdImage()
Checks if image was loaded from a `\GdImage` object (PHP 8.0+).
public
isImageGdImage() : bool
Tags
Return values
bool —isImageResource()
Checks if image was loaded from an image resource (PHP 7.4).
public
isImageResource() : bool
Tags
Return values
bool —isImageString()
Checks if image was loaded from image string.
public
isImageString() : bool
Tags
Return values
bool —isJPG()
Checks if image is a JPG.
public
isJPG() : bool
Tags
Return values
bool —isLocal()
Checks if image was loaded from local path.
public
isLocal() : bool
Tags
Return values
bool —isPNG()
Checks if image is a PNG.
public
isPNG() : bool
Tags
Return values
bool —load()
Loads an image from a local path, external url or image string.
public
load(string $src) : Image|static
Parameters
- $src : string
-
local path, external url or image string
Tags
Return values
Image|static —output()
Outputs the image on browser.
public
output() : Image|static
Tags
Return values
Image|static —preserve()
Preserves the resource image when save or output function is called.
public
preserve([bool $preserve = true ]) : Image|static
Parameters
- $preserve : bool = true
-
if it's true will preserve the resource image
Return values
Image|static —render()
Render the image in-memory and return the resource.
public
render() : resource
Tags
Return values
resource —| null Return the resource or null
resizeToHeight()
Resize image proportionally basing on the height of the image.
public
resizeToHeight(int $height) : Image|static
Parameters
- $height : int
Tags
Return values
Image|static —resizeToWidth()
Resize image proportionally basing on the width of the image.
public
resizeToWidth(int $width) : Image|static
Parameters
- $width : int
Tags
Return values
Image|static —rotate()
Rotate the image with a given angle.
public
rotate([int $angle = 0 ]) : Image|static
Parameters
- $angle : int = 0
Tags
Return values
Image|static —save()
Saves the image to specific path.
public
save([string $filename = null ]) : Image|static
Parameters
- $filename : string = null
-
if it's null save function will save the image in load path for default
Tags
Return values
Image|static —scale()
Scales the image.
public
scale([int|float $scale = 1 ]) : Image|static
Parameters
- $scale : int|float = 1
Tags
Return values
Image|static —setBoxHeight()
Sets height of box image.
public
setBoxHeight(int $height) : Image|static
Parameters
- $height : int
-
height
Tags
Return values
Image|static —setBoxLeft()
Sets left position of box image.
public
setBoxLeft(int $x) : Image|static
Parameters
- $x : int
-
left position
Tags
Return values
Image|static —setBoxTop()
Sets top position of box image.
public
setBoxTop(int $y) : Image|static
Parameters
- $y : int
-
top position
Tags
Return values
Image|static —setBoxWidth()
Sets width of box image.
public
setBoxWidth(int $width) : Image|static
Parameters
- $width : int
-
width
Tags
Return values
Image|static —setLeft()
Sets left position of image.
public
setLeft(int $x) : Image|static
Parameters
- $x : int
-
left
Tags
Return values
Image|static —setOpacity()
Sets opacity.
public
setOpacity(int $opacity) : Image|static
Parameters
- $opacity : int
-
Opacity value from 0 to 127
Tags
Return values
Image|static —setQuality()
Sets quality for image.
public
setQuality(int $quality) : Image|static
Parameters
- $quality : int
-
Quality value from 0 to 100
Tags
Return values
Image|static —setResource()
Sets image resource.
public
setResource(resource $resource) : Image|static
Parameters
- $resource : resource
-
resource
Tags
Return values
Image|static —setTop()
Sets top position of image.
public
setTop(int $y) : Image|static
Parameters
- $y : int
-
top
Tags
Return values
Image|static —toGIF()
Changes output format to GIF.
public
toGIF() : Image|static
Tags
Return values
Image|static —toJPG()
Changes output format to JPG.
public
toJPG() : Image|static
Tags
Return values
Image|static —toPNG()
Changes output format to PNG.
public
toPNG() : Image|static
Tags
Return values
Image|static —addOpacityFilter()
Add opacity filter to the current resource.
protected
addOpacityFilter() : void
Tags
Return values
void —drawImage()
Draw the an Image or Figure element.
private
drawImage(Image|Figure $element, mixed $canvas) : void
Parameters
Tags
Return values
void —drawText()
Draw a Text element.
private
drawText(Text $text, mixed $canvas) : void
Parameters
- $text : Text
-
text element
- $canvas : mixed
Tags
Return values
void —fetchImageContentFromURL()
Fetch an image string content from URL.
private
fetchImageContentFromURL(string $url) : string
Parameters
- $url : string
-
image URL
Tags
Return values
string —String data
isImageStringByString()
Checks if string is Image string.
private
isImageStringByString(string $imagestring) : bool
Parameters
- $imagestring : string
-
image string
Tags
Return values
bool —loadImageFromFile()
Load an image file from path.
private
loadImageFromFile(string $filepath) : void
Parameters
- $filepath : string
-
File path
Tags
Return values
void —loadImageFromResource()
Load an image from a resource or `\GdImage`.
private
loadImageFromResource(string $resource) : void
Parameters
- $resource : string
-
image resource or
\GdImage
Tags
Return values
void —loadImageFromString()
Load an image from image string.
private
loadImageFromString(string $imagestring) : void
Parameters
- $imagestring : string
-
Image string
Tags
Return values
void —loadImageFromURL()
Load an image from URL.
private
loadImageFromURL(string $url) : void
Parameters
- $url : string
-
Image URL
Tags
Return values
void —outputBuffer()
Output the image to either the browser or a file.
private
outputBuffer([string $filename = null ][, bool $output = false ]) : Image|static
Parameters
- $filename : string = null
-
[Optional] Path to save image
- $output : bool = false
-
[Optional] true to output the image
Tags
Return values
Image|static —| resource
outputBufferByImage()
private
outputBufferByImage(mixed $filename, mixed $quality) : mixed
Parameters
- $filename : mixed
- $quality : mixed
Tags
Return values
mixed —resize()
Resizes the image.
private
resize(int $width, int $height[, int $x1 = 0 ][, int $y1 = 0 ][, int $dstX = 0 ][, int $dstY = 0 ][, bool $isCrop = false ]) : Image|static
Parameters
- $width : int
-
image's width
- $height : int
-
image's height
- $x1 : int = 0
-
[Optional] Left position
- $y1 : int = 0
-
[Optional] Top position
- $dstX : int = 0
-
[Optional] x-coordinate of destination point
- $dstY : int = 0
-
[Optional] y-coordinate of destination point
- $isCrop : bool = false
-
[Optional] if it's true resize function will crop the image