Image
class Image (View source)
The Image object represents a resized (and cropped) copy of a given image.
Properties
$file | The filename of generated image. | ||
$height | The height of the generated image. | ||
$originalHeight | The height of the source image. | ||
$originalWidth | The width of the source image. | ||
$width | The width of the generated image. | ||
private | $crop | Cropping parameter. | |
private | $cropX | The pixels to crop the image on the X-axis on both sides. | |
private | $cropY | The pixels to crop the image on the Y-axis on both sides. | |
private | $fileFullPath | The full file system path to the generated image. | |
private | $originalFile | The filename of the source image | |
private | $requestedHeight | The desired height of the new image. (May not be the resulting width, depending on cropping or original image size) | |
private | $requestedWidth | The disired width of the new image. (May not be the resulting width, depending on cropping or original image size) | |
private | $type | The given image type. |
Methods
The constructor defines the main object properties from the given parameters and initiates the main methods.
Calculate the size and pixels to crop for the generated image.
Create a new (resized and cropped) image from the source image and save that image in AM_DIR_CACHE_IMAGES.
Determine the corresponding image file to a source file based on a md5 hash.
To verify, if the requested image is up to date, only the existence has to be tested, since any changes in the source image will be reflected in the filename's hash.
Details
at line 122
__construct(string $originalFile, float|null $requestedWidth = null, float|null $requestedHeight = null, bool $crop = false)
The constructor defines the main object properties from the given parameters and initiates the main methods.
at line 163
private
calculateSize()
Calculate the size and pixels to crop for the generated image.
at line 239
private
createImage()
Create a new (resized and cropped) image from the source image and save that image in AM_DIR_CACHE_IMAGES.
at line 311
private string
getImageCacheFilePath()
Determine the corresponding image file to a source file based on a md5 hash.
That hash is based on the source image's path, mtime, the new width and height and the cropping parameter. If one parameter changes, the hash will be different, which will result in recreating an image. Since the mtime is part of the hash, also any modification to the source image will be reflected in a different name. For each size and cropping setting, a unique filename will be returned, to clearly identify that setting.
at line 336
private
verifyCachedImage()
To verify, if the requested image is up to date, only the existence has to be tested, since any changes in the source image will be reflected in the filename's hash.