Alpha Framework 4.0.0 API Documentation

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
since
1.0
author

John Collins dev@alphaframework.org

license

http://www.opensource.org/licenses/bsd-license.php The BSD License

copyright

Copyright (c) 2021, John Collins (founder of Alpha Framework). All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.
* Neither the name of the Alpha Framework nor the names
  of its contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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
since
1.0

$height

The height of the image (can differ from the source file when scale=true).

private Integer $height
Tags
since
1.0

$logger

Trace logger.

private static Logger $logger = null
Tags
since
1.0

$quality

The quality of the jpg image generated (0.00 to 1.00, 0.75 by default).

private Double $quality
Tags
since
1.0

$scale

Flag to determine if the image will scale to match the target resolution (false by default).

private Boolean $scale
Tags
since
1.0

$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
since
1.0

$source

The absolute path to the source image.

private string $source
Tags
since
1.0

$sourceType

The file type of the source image (gif, jpg, or png supported).

private Enum $sourceType
Tags
since
1.0

$title

The title of the image for alt text (optional).

private string $title
Tags
since
1.0

$width

The width of the image (can differ from the source file when scale=true).

private Integer $width
Tags
since
1.0

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
throws
IllegalArguementException
since
1.0

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
since
1.0
Return values
string

getFilename()

Gets the auto-generated filename for the image in the /cache directory.

public getFilename() : string
Tags
since
1.0
Return values
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.

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
since
1.0
Return values
string

renderImage()

Renders the actual binary image using GD library calls.

public renderImage() : void
Tags
since
1.0

cache()

Caches the image to the cache directory.

private cache(GdImage $image) : void
Parameters
$image : GdImage

the binary GD image stream to save

Tags
since
1.0

checkCache()

Used to check the image cache for the image jpeg cache file.

private checkCache() : bool
Tags
since
1.0
Return values
bool

loadCache()

Method to load the content of the image cache file to the standard output stream (the browser).

private loadCache() : void
Tags
since
1.0

setFilename()

Setter for the filename, which also creates a sub-directory under /cache for images when required.

private setFilename() : void
Tags
since
1.0
throws
AlphaException

        
On this page

Search results