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.137

Twitter updates

  • ProcessWire 3.0.142 has a lot of updates but the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look at that, and also outline all of the new features in the just-released FormBuilder v40— More
    11 October 2019
  • This week’s dev branch version brings you improvements to ProcessWire’s input->cookie API variable, plus it adds the ability to modify system URLs and paths at runtime. This post also includes some examples to demonstrate just how useful this can be— More
    20 September 2019
  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019

Latest news

  • ProcessWire Weekly #284
    In the 284th issue of ProcessWire Weekly we're going to take a quick look at the latest core updates, introduce a new module called InputfieldFloatRange, and continue our ongoing poll series #processwireworks. Read on!
    Weekly.pw / 20 October 2019
  • ProcessWire 3.0.142 core updates
    This latest version of the core on the dev branch has a lot of updates, and the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look and also outline all of the new features in the just-released FormBuilder v40.
    Blog / 11 October 2019
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer