Detailed Description

ImageUtil provides support for image handling.

Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 29 of file ImageUtil.php.

Static Public Member Functions

static getImageTag ($imageFile, $widths, $type='w', $sizes='', $useDataAttributes=false, $alt='', $class='', $title='', array $data=[], $width=null, $fallbackFile='', $generate=false)
 
static getCachedImage ($location, $returnLocation=false, $callback=null)
 
static getCacheLocation ($imageFile, $width)
 
static invalidateCache ($imageFile)
 

Public Attributes

const IMAGE_CACHE_SECTION = 'images'
 

Member Function Documentation

◆ getImageTag()

static getImageTag (   $imageFile,
  $widths,
  $type = 'w',
  $sizes = '',
  $useDataAttributes = false,
  $alt = '',
  $class = '',
  $title = '',
array  $data = [],
  $width = null,
  $fallbackFile = '',
  $generate = false 
)
static

Create an HTML image tag using srcset and sizes attributes.

The original image is supposed to be located inside the upload directory of the application (Media configuration section). The image locations in the srcset attribute will point to the frontend cache directory (FrontendCache configuration section).

Parameters
$imageFileThe image file location relative to the upload directory
$widthsArray of sorted width values to be used in the srcset attribute
$typeIndicates how width values should be used (optional, default: w)
  • w: Values will be used as pixels, e.g. widths="1600,960" results in srcset="... 1600w, ... 960w"
  • x: Values will be used as pixel ration, e.g. widths="1600,960" results in srcset="... 2x, ... 1x"
$sizesString of media queries to define image size in relation of the viewport (optional)
$useDataAttributesBoolean indicating whether to replace src, srcset, sizes by data-src, data-srcset, data-sizes (optional, default: false)
$altAlternative text (optional)
$classImage class (optional)
$titleImage title (optional)
$dataData attributes as key/value pairs
$widthWidth in pixels to output for the width attribute, the height attribute will be calculated according to the aspect ration (optional)
$fallbackFileThe image file to use, if imageFile does not exist (optional)
$generateBoolean indicating whether to generate the images or not (optional, default: false)
Returns
String

Definition at line 56 of file ImageUtil.php.

◆ getCachedImage()

static getCachedImage (   $location,
  $returnLocation = false,
  $callback = null 
)
static

Output the cached image for the given cache location.

Parameters
$location
$returnLocationBoolean indicating if only the file location should be returned (optional)
$callbackFunction called, after the cached image is created, receives the original and cached image as parameters (optional)
Returns
String, if returnLocation is true

Definition at line 160 of file ImageUtil.php.

◆ getCacheLocation()

static getCacheLocation (   $imageFile,
  $width 
)
static

Get the cache location for the given image and width.

Parameters
$imageFileImage file located inside the upload directory of the application given as path relative to WCMF_BASE
$width
Returns
String

Definition at line 212 of file ImageUtil.php.

◆ invalidateCache()

static invalidateCache (   $imageFile)
static

Delete the cached images for the given image file.

Parameters
$imageFileImage file located inside the upload directory of the application given as path relative to WCMF_BASE

Definition at line 227 of file ImageUtil.php.

Member Data Documentation

◆ IMAGE_CACHE_SECTION

const IMAGE_CACHE_SECTION = 'images'

Definition at line 31 of file ImageUtil.php.