ImageProcessingInstructions
A DTO representing all information needed to process an image, mainly the target dimensions.
With this information an image can be processed by ImageMagick/GraphicsMagick.
"cropScaling" refers to the logic where the image is cropped and scaled at the same time, which was used back in TYPO3 v3/v4 but the "LocalCropScaleMaskHelper" is actually doing this in subsequent steps, but should be merged together again once there is a load of more tests.
This object is still internal as long as cropping isn't migrated yet to the Crop API.
Table of Contents
Properties
Methods
- __construct() : mixed
- fromCropScaleValues() : self
- Get numbers for scaling the image based on input.
- fromProcessingTask() : ImageProcessingInstructions
Properties
$cropArea
public
Area|null
$cropArea
= null
$height
public
int
$height
= 0
$width
public
int
$width
= 0
Methods
__construct()
public
__construct([int<0, max> $width = 0 ][, int<0, max> $height = 0 ][, Area|null $cropArea = null ]) : mixed
Parameters
- $width : int<0, max> = 0
- $height : int<0, max> = 0
- $cropArea : Area|null = null
fromCropScaleValues()
Get numbers for scaling the image based on input.
public
static fromCropScaleValues(int<0, max> $incomingWidth, int<0, max> $incomingHeight, int<0, max>|string $width, int<0, max>|string $height, array<string|int, mixed> $options) : self
Notes by Benni in 2023 in order to understand this magic:
Relevant if an image should be
- scaled
- cropped
- keep the aspect ratio while scaling?
- use a target width or height
- or rather have a minimum or maximum width and/or height
This method does a lot of magic:
- $incomingWidth/$incomingHeight contains the size of an original image for example.
- $w and $h are the width and height that are originally required the image to be like when scaled. They could contain a "c" for cropping information or "m" for "Ensure that even though $w and $h are given, one containing an $m that we keep the aspect ratio." "m" really allows to say $w="50c" that this might in a result with [0]=100 because $w would follow $h in order to keep aspect ratio. Obviously this only works properly if both m and c are working
- $options contain "maxW" (never go beyond this width, even if scaling larger as this), same with "maxH" and "minW" and "minH"
The return values are a bit tricky to understand, so I added a few tests:
-
AFAICS "0" and "1" are always used as "these are the target width / height" which my image should be scaled to, or cropped down to. Notes: If you hand in $info[0] and $incomingHeight a "0", you will get "0" as return value back! but
-
"crs" if the image should be cropped (which is indicated by one of $w or $h contain the "c" at the end)
-
"cropH" and "cropV" is also set when one of the incoming $w or $h contains a "c". Notes: "cropH" and "cropV" are rather cryptic, and can't really be used outside of this context. They are then "magically calculated" outside of this function $offsetX = (int)(($data[0] - $data['origW']) * ($data['cropH'] + 100) / 200); $offsetY = (int)(($data[1] - $data['origH']) * ($data['cropV'] + 100) / 200);
-
"origW" / "origH" seems to be the values that were handed in as $w and $h, but they might be altered f.e. "origH" is set when $w is given and $options["maxH"]
-
When such a rearranging calculation was made ("maxH" reduces the original $w due to constraints), then the return value "max" is set.
-
When using the "c" argument, origH and origW seem to contain the values that you would expect when NOT doing a crop scenario whereas $incomingWidth and $incomingHeight contain the target width and height that could be larger than originally requested.
Parameters
- $incomingWidth : int<0, max>
-
the width of an original image for example, can be "0" if there is no original image
- $incomingHeight : int<0, max>
-
the height of an original image for example, can be "0" if there is no original image
- $width : int<0, max>|string
-
"required" width that is requested, can be "" or "0" or a number of a magic "m" or "c" appended
- $height : int<0, max>|string
-
"required" height that is requested, can be "" or "0" or a number of a magic "m" or "c" appended
- $options : array<string|int, mixed>
-
Options: Keys are like "maxW", "maxH", "minW", "minH"
Return values
selffromProcessingTask()
public
static fromProcessingTask(TaskInterface $task) : ImageProcessingInstructions
Parameters
- $task : TaskInterface