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 #548
    In the 548th issue of ProcessWire Weekly we're going to check out a couple of new third party modules, introduce the latest ProcessWire core updates, and more. Read on!
    Weekly.pw / 9 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH