Helper class: Imengine

This class generates correct urls for the service Imengine. It helps you to add the appropriate parameters to generate images according to you needs.

Full name: \Infomaker\Imengine\Imengine

Setup and configuration

This class needs an Imengine to build correct urls. To set the correct Imengine you use the setup method:

Imengine::setup(string $serverUrl): void;

Parameters:

Parameter

Type

Description

$serverUrl

string

The Imengine url to base all built request-urls.

Setup and configuration from Base theme

This is done setup from the ThemeStartup. The Imengine server is configured in the Everyware plugin under Open Content->OC Settings in wp-admin.

To set the Imengine server url on a network level use the variable CF_IMENGINE in the .env-file. This will be used as default if the server has not been configured in the OC Settings

example:

CF_IMENGINE=https://imengine.public.infomaker.io

Standard usage

The class is used as a static instance. You create an instance through one of the static functions found bellow.

Required methods:

We have two available ways to specify the src of the image. For this we use one of the following methods:

fromUuid

Defines what src that Imengine will manipulate

Imengine::fromUuid(string $uuid): string;

Parameters:

Parameter

Type

Description

$uuid

string

The uuid of the image in Open Content.

fromSrc

Defines what src that Imengine will manipulate

Imengine::fromSrc(string $imgSrc): string;

Parameters:

Parameter

Type

Description

$imgSrc

string

The url to an external image.

Example:

$imageSrc = Imengine::original()->fromUuid($uuid);

//or

$imageSrc = Imengine::original()->fromSrc($imgSrc);

Static functions

create

Create url from scratch by using parameters provided

Imengine::create(array $params = null): $this

Parameters:

Parameter

Type

Description

$params

array

Optional. Parameters to send forth to the Imengine url (default=null)

createMirrorFunction

Create an instance with only the function to mirror and params. This method is used by all static functions to mirror Imengine server-functions.

Imengine::createMirrorFunction(string $func, array $params = null): $this

Parameters:

Parameter

Type

Description

$func

string

The Imengine server-function to use

$params

array

Optional. Parameters to send forth to the Imengine url (default=null)

Mirrored functions

These static methods are used to instantiate the Imengine class. They mirror the functions found on Imengine API

cover

Uses the original image ratio and customize the width or height to scale image within the specified limits.

Imengine::cover(int $width = null, int $height = null): $this

Parameters:

Parameter

Type

Description

$width

int

Optional. limits the width to amount in pixels (default=null)

$height

int

Optional. limits the height to amount in pixels (default=null)

cropResize

Crop image into defined crop-size from custom start-positions. Then scale into defined size.

Imengine::cropResize(CropResizeDataInterface $cropData): $this

Uses: \Infomaker\Imengine\CropData\Interfaces\CropResizeDataInterface

Parameters:

Parameter

Type

Description

$cropData

CropResizeDataInterface

An interface from where the necessary data can be extracted.

fit

Scale image to fit inside the limits. Add scale up to make the image cover the maxsize-area (Can exceed limits on scale up)

Imengine::fit(int $maxSize, bool $scaleUp = true): $this

Parameters:

Parameter

Type

Description

$maxsize

int

The limits to for height and width

$scaleUp

boolean

Optional. Whether to make the resulted image cover the maxsize-area. This option can exceed limits. (default=TRUE)

hardcrop

Crop image into defined size top left position

Imengine::hardCrop(int $width, int $height): $this

Parameters:

Parameter

Type

Description

$width

int

Resulted width

$height

int

Resulted height

newsPilotCrop

Crop image into defined size from custom start-positions. Implemented as crop for NewsPilot

Imengine::newsPilotCrop(NewsPilotCropDataInterface $cropData): $this

Uses: \Infomaker\Imengine\CropData\Interfaces\NewsPilotCropDataInterface

Parameters:

Parameter

Type

Description

$cropData

NewsPilotCropDataInterface

An interface from where the necessary data can be extracted.

original

Fetch image with original size.

Imengine::original(): $this

Parameters: No parameters

thumbnail

Crop image into defined size from center position

Imengine::thumbnail(int $width, int $height): $this

Parameters:

Parameter

Type

Description

$width

int

Resulted width

$height

int

Resulted height

ratio

Crop image into given ratio using "hardcrop".

Imengine::ratio(int $width, string $ratio = null): $this

Parameter

Type

Description

$width

int

Resulted width

$ratio

string

Optional. The ratio from which to calculate the height. (default='3:2')

autoCrop

Crop image into given ratio from center. Uses the original sizes of the image to calculate the values needed for "cropresize"

Imengine::autoCrop(AutoCropDataInterface $cropData): $this

Uses: \Infomaker\Imengine\CropData\Interfaces\AutoCropDataInterface

Parameters:

Parameter

Type

Description

$cropData

AutoCropDataInterface

An interface from where the necessary data can be extracted.

square

Crop image into a square using "hardcrop".

Imengine::square(int $size): $this

Parameters:

Parameter

Type

Description

$size

int

Resulted height and width

raw

Function for fetching the Raw format of the image (May have an unlimited size) This function is only available for images from Open Content.

Imengine::raw(string $uuid, int $quality = null): string

Parameters:

Parameter

Type

Description

$uuid

string

The uuid of the

$quality

int

Optional. The quality in percent of the resulted image. (default=100)

Chainable functions

These functions add options to chain on mirror functions to further manipulate your query before sending it to Imengine.

with

Add or override parameters not specific to the function being used

Imengine::with(array $params): string;

Parameters:

Parameter

Type

Description

$params

array

Optional. Parameters to send forth to the Imengine url.

quality

Allow for quality change of the requested image

Imengine::quality(int $quality): $this;

Parameters:

Parameter

Type

Description

$quality

int

The quality in percent (1-100) for the resulted image.

format

Set the format of the requested image. Imengine will default to jpg

Imengine::format(string $format): $this;

Parameters:

Parameter

Type

Description

$format

string

The format of the resulted image (jpg

png). (default='jpg')

Last updated