Skip to content

Gravity

Sets the anchor for cropping and extending. Offsets of 1 or more are absolute pixels, offsets below 1 are relative.

imgproxy: gravity (alias g) · Availability: all editions; the obj and objw types need Pro

use SomehowDigital\ImgProxy\Url;
use SomehowDigital\ImgProxy\Option\Gravity;
use SomehowDigital\ImgProxy\Option\GravityEnum;
$url = Url::create()
->source('https://example.com/image.jpg')
->options(new Gravity(GravityEnum::NORTH_EAST, 10, 20));
$url->build();
// _/g:noea:10:20/plain/https%3A%2F%2Fexample.com%2Fimage.jpg

The option appears in the URL as g:noea:10:20.

Parameter Type Default Description
$gravity GravityEnum|string required A GravityEnum case or its value, such as no, ea, so, we, noea, nowe, soea, sowe or ce.
$horizontal float — Horizontal offset.
$vertical float — Vertical offset.

A dash means the argument can be left out. Trailing arguments that are left out or null are dropped from the URL, while a null before a given argument leaves an empty slot, so the following arguments keep their position.

  • For smart, focus point and object gravity, prefer the dedicated classes GravitySmart, GravityFocusPoint, GravityObject and GravityObjectWeight.

imgproxy reference