Pageimage::focus() method

Get or set focus area for crops to use

These settings are used by $this->size() calls that specify BOTH width AND height. Focus helps to ensure that the important subject of the photo is not cropped out when the requested size proportion differs from the original image proportion. For example, not chopping off someone’s head in a photo.

Default behavior is to return an array containing "top" and "left" indexes, representing percentages from top and left. When arguments are specified, you are either setting the top/left percentages, or unsetting focus, or getting focus in different ways, described in arguments below.

A zoom argument/property is also present here for future use, but not currently supported.

Usage

// basic usage
$array = $pageimage->focus();

// usage with all arguments
$array = $pageimage->focus($top = null, $left = null, $zoom = null);

Arguments

NameType(s)Description
top (optional)null, float, int, array, false

Omit to get focus array, or specify one of the following:

  • GET: Omit all arguments to get focus array (default behavior).
  • GET: Specify boolean TRUE to return TRUE if focus data is present or FALSE if not.
  • GET: Specify integer 1 to make this method return pixel dimensions rather than percentages.
  • SET: Specify both $top and $left arguments to set (values assumed to be percentages).
  • SET: Specify array containing "top" and "left" indexes to set (percentages).
  • SET: Specify array where index 0 is top and index 1 is left (percentages).
  • SET: Specify string in the format "top left", i.e. "25 70" or "top left zoom", i.e. "25 70 30" (percentages).
  • SET: Specify CSV key=value string in the format "top=25%, left=70%, zoom=30%" in any order
  • UNSET: Specify boolean false to remove any focus values.
left (optional)null, float, int

Set left value (when $top value is float|int)

  • This argument is only used when setting focus and should be omitted otherwise.
zoom (optional)null, int

Zoom percent (not currently supported)

Return value

array bool Pageimage

Returns one of the following:

  • When getting returns array containing top, left and default properties.
  • When TRUE was specified for the $top argument, it returns either TRUE (has focus) or FALSE (does not have).
  • When setting or unsetting returns $this.

Pageimage methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #518
    The 518th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 13 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits