trait ResizeImage

Resize and cache copies of image files to allow them to be used at different sizes in templates.

Methods

string
cachedImage(int $width = 0, int $height = 0)

Resizes and caches an associated image and returns a URL to the cached copy.

Details

at line 48
string cachedImage(int $width = 0, int $height = 0)

Resizes and caches an associated image and returns a URL to the cached copy.

Allows arbitrary sized thumbnails to be produced from the object's image property. These are saved in the cache for future lookups. Image proportions are always preserved, so if both width and height are specified, the larger dimension will take precedence for resizing and the other will be ignored.

Usually, you want to produce an image of a specific width or (less commonly) height to meet a template/presentation requirement.

Requires GD library.

Parameters

int $width Width of the cached image output.
int $height Height of the cached image output.

Return Value

string $url URL to the cached image.