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

Twitter updates

  • New post: Quietly and without interruption this week, the ProcessWire.com website (and all subdomains) moved from a single static server to a load-balanced multi-server environment, giving us even more horsepower and redundancy than before— More
    19 April 2019
  • New post: With ProcessWire 3.0.130, this week we’ll take a detailed look at a few useful new API additions made in the last few weeks, along with examples of each—More
    12 April 2019
  • New post: This week ProcessWire ProMailer has been released, plus we’ve got a nice upgrade in our community support forum, and more— More
    15 March 2019

Latest news

  • ProcessWire Weekly #258
    In the 258th issue of ProcessWire Weekly we'll cover a hosting upgrade for the processwire.com site and it's subdomains, introduce PW Review and Terminal module, and feature the new site of O'Neil Cinema. Read on!
    Weekly.pw / 20 April 2019
  • ProcessWire.com website hosting upgrades
    Quietly and without interruption this week, our whole website moved from a single static server to a load-balanced multi-server environment, giving us even more horsepower and redundancy than before.
    Blog / 19 April 2019
  • Subscribe to weekly ProcessWire news

“…building with ProcessWire was a breeze, I really love all the flexibility the system provides. I can’t imagine using any other CMS in the future.” —Thomas Aull