Image
in package
A widget that can generate an image which is scaled to the screen resolution of the user, and can be made secured to prevent hot-linking from remote sites. Note that by default, a jpg file will be returned (the source file can be jpg, png, or gif).
Tags
Table of Contents
Properties
- $filename : string
- The auto-generated name of the cache file for the image.
- $height : Integer
- The height of the image (can differ from the source file when scale=true).
- $logger : Logger
- Trace logger.
- $quality : Double
- The quality of the jpg image generated (0.00 to 1.00, 0.75 by default).
- $scale : Boolean
- Flag to determine if the image will scale to match the target resolution (false by default).
- $secure : Boolean
- Flag to determine if the link to the image will change every 24hrs, making hot-linking to the image difficult (false by default).
- $source : string
- The absolute path to the source image.
- $sourceType : Enum
- The file type of the source image (gif, jpg, or png supported).
- $title : string
- The title of the image for alt text (optional).
- $width : Integer
- The width of the image (can differ from the source file when scale=true).
Methods
- __construct() : mixed
- The constructor.
- convertImageURLToPath() : string
- Converts a URL for an image to a relative file system path for the image, assuming it is hosted on the same server as the application. Returns the path of the image.
- getFilename() : string
- Gets the auto-generated filename for the image in the /cache directory.
- renderHTMLLink() : string
- Renders the HTML <img> tag to the ViewImage controller, with all of the correct params to render the source image in the desired resolution.
- renderImage() : void
- Renders the actual binary image using GD library calls.
- cache() : void
- Caches the image to the cache directory.
- checkCache() : bool
- Used to check the image cache for the image jpeg cache file.
- loadCache() : void
- Method to load the content of the image cache file to the standard output stream (the browser).
- setFilename() : void
- Setter for the filename, which also creates a sub-directory under /cache for images when required.
Properties
$filename
The auto-generated name of the cache file for the image.
private
string
$filename
Tags
$height
The height of the image (can differ from the source file when scale=true).
private
Integer
$height
Tags
$logger
Trace logger.
private
static Logger
$logger
= null
Tags
$quality
The quality of the jpg image generated (0.00 to 1.00, 0.75 by default).
private
Double
$quality
Tags
$scale
Flag to determine if the image will scale to match the target resolution (false by default).
private
Boolean
$scale
Tags
$secure
Flag to determine if the link to the image will change every 24hrs, making hot-linking to the image difficult (false by default).
private
Boolean
$secure
Tags
$source
The absolute path to the source image.
private
string
$source
Tags
$sourceType
The file type of the source image (gif, jpg, or png supported).
private
Enum
$sourceType
Tags
$title
The title of the image for alt text (optional).
private
string
$title
Tags
$width
The width of the image (can differ from the source file when scale=true).
private
Integer
$width
Tags
Methods
__construct()
The constructor.
public
__construct(string $source, int $width, int $height, string $sourceType[, float $quality = 0.75 ][, bool $scale = false ][, bool $secure = false ]) : mixed
Parameters
- $source : string
- $width : int
- $height : int
- $sourceType : string
- $quality : float = 0.75
- $scale : bool = false
- $secure : bool = false
Tags
convertImageURLToPath()
Converts a URL for an image to a relative file system path for the image, assuming it is hosted on the same server as the application. Returns the path of the image.
public
static convertImageURLToPath(string $imgURL) : string
Parameters
- $imgURL : string
Tags
Return values
stringgetFilename()
Gets the auto-generated filename for the image in the /cache directory.
public
getFilename() : string
Tags
Return values
stringrenderHTMLLink()
Renders the HTML <img> tag to the ViewImage controller, with all of the correct params to render the source image in the desired resolution.
public
renderHTMLLink([string $altText = '' ]) : string
Parameters
- $altText : string = ''
-
Set this value to render alternate text as part of the HTML link (defaults to no alternate text)
Tags
Return values
stringrenderImage()
Renders the actual binary image using GD library calls.
public
renderImage() : void
Tags
cache()
Caches the image to the cache directory.
private
cache(GdImage $image) : void
Parameters
- $image : GdImage
-
the binary GD image stream to save
Tags
checkCache()
Used to check the image cache for the image jpeg cache file.
private
checkCache() : bool
Tags
Return values
boolloadCache()
Method to load the content of the image cache file to the standard output stream (the browser).
private
loadCache() : void
Tags
setFilename()
Setter for the filename, which also creates a sub-directory under /cache for images when required.
private
setFilename() : void