Rundiz\Image

Crop extends AbstractGdCommand
in package
uses CalculationTrait, GdTrait

Crop

Tags
since
3.1.0

Table of Contents

Properties

$Gd  : Gd

Methods

__construct()  : mixed
execute()  : bool
Execute the command.
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).
fillTransparentOnObject()  : mixed
Fill transparent-white on selected image object.
fillWhiteBgOnDestination()  : mixed
Fill white background on destination image object.
isResourceOrGDObject()  : bool
Check if image variable is resource of GD or is object of `\GdImage` (PHP 8.0) or not.
setErrorMessage()  : mixed
Set error message and code. This will be set statusXxx properties.
setStatusSuccess()  : mixed
Set status as success and remove error message, error code.
setupSourceFromFile()  : GdImage|resource|false
Setup source image object (GD) from file.
getImageColorAlpha()  : mixed
Get image color with alpha value (transparency).

Properties

Methods

execute()

Execute the command.

public execute(mixed $width, mixed $height[, mixed $start_x = '0' ][, mixed $start_y = '0' ][, mixed $fill = 'transparent' ]) : bool
Parameters
$width : mixed
$height : mixed
$start_x : mixed = '0'
$start_y : mixed = '0'
$fill : mixed = 'transparent'
Return values
bool

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.

fillTransparentOnObject()

Fill transparent-white on selected image object.

protected fillTransparentOnObject(GdImage|resource $image) : mixed
Parameters
$image : GdImage|resource

Image object to fill color.

Tags
since
3.1.4

fillWhiteBgOnDestination()

Fill white background on destination image object.

protected fillWhiteBgOnDestination() : mixed

Create temporary canvas, fill white background, copy image from "destination image object" to temp canvas, then mark this canvas as "destination image object".

isResourceOrGDObject()

Check if image variable is resource of GD or is object of `\GdImage` (PHP 8.0) or not.

protected isResourceOrGDObject(mixed $image) : bool
Parameters
$image : mixed

The \GdImage variable to check.

Tags
since
3.0.2

Moved from \Rundiz\Image\Drivers\Gd

Return values
bool

Return true if it is resource or instance of \GdImage, return false if it is not.

setErrorMessage()

Set error message and code. This will be set statusXxx properties.

protected setErrorMessage(string $errorMessage, int $errorCode) : mixed
Parameters
$errorMessage : string

The error message.

$errorCode : int

The error code, usually it is class's constant.

Tags
since
3.1.4
see
AbstractImage::setErrorMessage()
throws
InvalidArgumentException

Throw the exception if argument type is invalid.

setStatusSuccess()

Set status as success and remove error message, error code.

protected setStatusSuccess() : mixed
Tags
since
3.1.4
see
AbstractImage::setStatusSuccess()

setupSourceFromFile()

Setup source image object (GD) from file.

protected setupSourceFromFile(string $file, int $imageType) : GdImage|resource|false
Parameters
$file : string

Source image file path.

$imageType : int

Image type as defined in IMAGETYPE_XXX by PHP. This value may have got from getImageFileData() method.

Tags
since
3.1.4
Return values
GdImage|resource|false

Return resource or \GdImage (for PHP 8.0+) on success, false on failure.

getImageColorAlpha()

Get image color with alpha value (transparency).

private getImageColorAlpha(string $colorName, int $alpha, GdImage|resource $image) : mixed
Parameters
$colorName : string

The color name. Supported 'black', 'white', 'red', 'green', 'blue', 'yellow', 'cyan', 'magenta'.

$alpha : int

The alpha value from 0 (no transparent) to 127 (full transparent).

$image : GdImage|resource

The GD image object or resource.

Tags
since
3.2.0
throws
InvalidArgumentException

Throw exception if provide argument type mismatch.


        
On this page

Search results