Pageimage::isVariation() method

Given a file name (basename), return array of info if this is a variation for this instance’s file, or false if not.

Returned array includes the following indexes:

  • original (string): Original basename
  • url (string): URL to image
  • path (string): Full path + filename to image
  • width (int): Specified width in filename
  • height (int): Specified height in filename
  • actualWidth (int): Actual width when checked manually
  • actualHeight (int): Acual height when checked manually
  • crop (string): Cropping info string or blank if none
  • suffix (array): Array of suffixes

The following are only present if variation is based on another variation, and thus has a parent variation image between it and the original:

  • suffixAll (array): Contains all suffixes including among parent variations
  • parent (array): Variation info array of direct parent variation file

Usage

// basic usage
$bool = $pageimage->isVariation(string $basename);

// usage with all arguments
$bool = $pageimage->isVariation(string $basename, $options = []);

Arguments

NameType(s)Description
basenamestring

Filename to check (basename, which excludes path)

options (optional)array, bool

Array of options to modify behavior, or boolean to only specify allowSelf option.

  • allowSelf (bool): When true, it will return variation info even if same as current Pageimage. (default=false)
  • verbose (bool): Return verbose array of info? If false, just returns basename (string) or false. (default=true)

Return value

bool string array

Returns false if not a variation, or array (verbose) or string (non-verbose) of info if it is.


Hooking Pageimage::isVariation(…)

You can add your own hook events that are executed either before or after the Pageimage::isVariation(…) method is executed. Examples of both are included below. A good place for hook code such as this is in your /site/ready.php file.

Hooking before

The 'before' hooks are called immediately before each Pageimage::isVariation(…) method call is executed. This type of hook is especially useful for modifying arguments before they are sent to the method.

$this->addHookBefore('Pageimage::isVariation', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $Pageimage = $event->object;

  // Get values of arguments sent to hook (and optionally modify them)
  $basename = $event->arguments(0);
  $options = $event->arguments(1);

  /* Your code here, perhaps modifying arguments */

  // Populate back arguments (if you have modified them)
  $event->arguments(0, $basename);
  $event->arguments(1, $options);
});

Hooking after

The 'after' hooks are called immediately after each Pageimage::isVariation(…) method call is executed. This type of hook is especially useful for modifying the value that was returned by the method call.

$this->addHookAfter('Pageimage::isVariation', function(HookEvent $event) {
  // Get the object the event occurred on, if needed
  $Pageimage = $event->object;

  // An 'after' hook can retrieve and/or modify the return value
  $return = $event->return;

  // Get values of arguments sent to hook (if needed)
  $basename = $event->arguments(0);
  $options = $event->arguments(1);

  /* Your code here, perhaps modifying the return value */

  // Populate back return value, if you have modified it
  $event->return = $return;
});

Pageimage methods and properties

API reference based on ProcessWire core version 3.0.163

Twitter updates

  • What's coming in ProcessWire 3.0.165, plus a brief preview ProCache and FormBuilder versions coming within the next couple of weeks— More
    14 August 2020
  • This week we’re proud to announce the newest ProcessWire master version 3.0.164. Relative to the previous master (3.0.148) this version adds a ton of new & useful features and fixes more than 85 issues, with more than 225 commits over 7 months— More
    7 August 2020
  • ProcessWire 3.0.163 resolves more than a dozen issue reports and adds new hooks and configurable module install options, among numerous other updates. In addition, a major update to ProCache (v4.0) has been released— More
    24 July 2020

Latest news

  • ProcessWire Weekly #327
    In the 327th issue of ProcessWire Weekly we're going to check out the latest core updates, introduce a new module called Lister Selector, and check out the website of creative animation studio Volstok. Read on!
    Weekly.pw / 15 August 2020
  • ProcessWire 3.0.164 new master version
    This week we’re proud to announce the newest ProcessWire master version 3.0.164. Relative to the previous master version (3.0.148) this version adds a ton of new and useful features and fixes more than 85 issues, with more than 225 commits over a period of 7 months.
    Blog / 7 August 2020
  • Subscribe to weekly ProcessWire news

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer