Rundiz\Image

Calculation
in package
uses CalculationTrait

Calculation class.

Tags
since
3.1.5

Table of Contents

Methods

calculateNewDimensionByRatio()  : mixed
Calculate new dimension by aspect ratio.
calculateWidthHeightIndependent()  : array<string|int, mixed>
Calculate both width and height by aspect ratio independently.
calculateCounterClockwise()  : int
Calculate counter clockwise degree.
calculateStartXOfCenter()  : int
Calculate startX position of center.
calculateWatermarkImageStartXY()  : array<string|int, mixed>
Calculate watermark start X and Y from specified text position (left, right, bottom, top, middle, center).
convertAlpha127ToRgba()  : string
Convert alpha number (0 - 127) to rgba value (1.00 - 0.00).
getSourceImageOrientation()  : string
Get source image orientation.

Methods

calculateNewDimensionByRatio()

Calculate new dimension by aspect ratio.

public calculateNewDimensionByRatio(number $source_image_width, number $source_image_height, number $new_width, number $new_height[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$source_image_width : number

Original image width.

$source_image_height : number

Original image height.

$new_width : number

New image width.

$new_height : number

New image height.

$options : array<string|int, mixed> = []

Associative array:
master_dim (string) Master dimension. The value is same as in Rundiz\Image\AbstractProperties class. Default is 'auto'.
allow_resize_larger (bool) Allow to resize larger than source dimension. The value is same as in Rundiz\Image\AbstractProperties class. Default is false.

Tags
throws
InvalidArgumentException

Throw the exception of argument is invalid type.

calculateWidthHeightIndependent()

Calculate both width and height by aspect ratio independently.

public calculateWidthHeightIndependent(number $source_image_width, number $source_image_height, number $new_width, number $new_height) : array<string|int, mixed>

This will be calculate new height for specified $new_width and also calculate new width for specified $new_height.

For example: original image dimension is 1920x1080.
Enter new width as 800 and calculated new height will be 450.
When you use, for master dimension based on width, use calculated new height only (450).
So, your new dimension will be 800x450.

The same goes for new height.
Enter new height as 800 and calculated new width will be 1422.
When you use, for master dimension based on height, use calculated new width only (1422).
So, your new dimension will be 1422x800.

Parameters
$source_image_width : number

Original image width.

$source_image_height : number

Original image height.

$new_width : number

New image width.

$new_height : number

New image height.

Tags
throws
InvalidArgumentException

Throw the exception of argument is invalid type.

Return values
array<string|int, mixed>

Return indexed array where index 0 is calculated width (integer), index 1 is calculated height (integer).

calculateCounterClockwise()

Calculate counter clockwise degree.

protected calculateCounterClockwise(int $value) : int

Calculate input degree for use with Imagick.
In GD 90 degrees is 270 in Imagick. This function help to make it working together very well.

So it will be...
input = output
0 = 0
1 = 359
10 = 350
90 = 270
180 = 180
270 = 90
360 = 0

Parameters
$value : int

Input degrees.

Return values
int

Return opposite degrees for use with Imagick.

calculateStartXOfCenter()

Calculate startX position of center.

protected calculateStartXOfCenter(int $objWidth, int $canvasWidth) : int

With this method, you can calculate the start x position of center (horizontal) or middle (vertical).
The purpose of this method is for internal use, do not call this method from image's driver class directly due to it can be changed in the future.

Formular: round((half of canvas) - (half of object))

Parameters
$objWidth : int

Destination image object size.

$canvasWidth : int

Canvas size.

Return values
int

Calculated size.

calculateWatermarkImageStartXY()

Calculate watermark start X and Y from specified text position (left, right, bottom, top, middle, center).

protected calculateWatermarkImageStartXY(string $wmStartX, string $wmStartY, int $imgWidth, int $imgHeight, int $wmWidth, int $wmHeight[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>

The purpose of this method is for internal use, do not call this method from image's driver class directly due to it can be changed in the future.

Parameters
$wmStartX : string

Position to begin in x axis. The value is 'left', 'center', 'right'.

$wmStartY : string

Position to begin in y axis. The value is 'top', 'middle', 'bottom'.

$imgWidth : int

Latest image width. Get the dimension from latest modified image only.

$imgHeight : int

Latest image height. Get the dimension from latest modified image only.

$wmWidth : int

Latest watermark image width. Get the dimension from latest modified image only.

$wmHeight : int

Latest watermark image height. Get the dimension from latest modified image only.

$options : array<string|int, mixed> = []

The watermark options. This argument must be normalized before calling this method. Value is associative array.
padding (int) Padding around watermark object. Use with left, right, bottom, top but not middle, center.

Tags
throws
InvalidArgumentException

Throw exception if invalid argument type was specified.

Return values
array<string|int, mixed>

Return array with width as index 0, height as index 1.

convertAlpha127ToRgba()

Convert alpha number (0 - 127) to rgba value (1.00 - 0.00).

protected convertAlpha127ToRgba(int $number) : string

The purpose of this method is for internal use, do not call this method from image's driver class directly due to it can be changed in the future.

Parameters
$number : int

Alpha number (0 to 127). 127 is completely transparent.

Return values
string

Return RGBA value (1.00 to 0.00). 0.00 is completely transparent.

getSourceImageOrientation()

Get source image orientation.

protected getSourceImageOrientation(number $source_image_width, number $source_image_height) : string

This method was called by calculateNewDimensionByRatio().

Parameters
$source_image_width : number

Original image width.

$source_image_height : number

Original image height.

Tags
throws
InvalidArgumentException

Throw the exception of argument is invalid type.

Return values
string

Return 'S' for square, 'L' for landscape, 'P' for portrait.


        
On this page

Search results