Gd
extends AbstractImage
in package
uses
GdTrait
GD driver for image manipulation.
Tags
Table of Contents
Constants
- RDIERROR_CALCULATEFAILED_USE_RESIZENORATIO = 4
- Unable to calculated, please try to calculate on your own and use `resizeNoRatio()` instead.
- RDIERROR_CROP_UNKNOWNIMG = 5
- Unable to crop this kind of image.
- RDIERROR_FLIP_NOTSUPPORTED = 9
- Not support flip for current PHP version. (PHP 5.5 or newer is required to use GD flip.)
- RDIERROR_FLIP_UNKNOWIMG = 8
- Unable to flip this kind of image.
- RDIERROR_IMAGEMAGICK_NOTMEETREQUIREMENT = 21
- ImageMagick version does not meet requirement.
- RDIERROR_IMAGICK_NOTLOAD = 18
- Imagick extension was not loaded.
- RDIERROR_IMAGICK_NOTMEETREQUIREMENT = 19
- Imagick version does not meet requirement.
- RDIERROR_IMAGICK_VERSIONUNKNOW = 20
- Could not verify Imagick version.
- RDIERROR_RESIZE_UNKNOWIMG = 6
- Unable to resize this kind of image.
- RDIERROR_ROTATE_UNKNOWIMG = 7
- Unable to rotate this kind of image.
- RDIERROR_SAVE_FAILED = 13
- Failed to save an image.
- RDIERROR_SAVE_UNSUPPORT = 12
- Unable to save to this extension. or target file extension is not supported.
- RDIERROR_SHOW_FAILED = 15
- Failed to show an image to browser.
- RDIERROR_SHOW_UNSUPPORT = 14
- Unable to show image in this extension. File extension is not supported.
- RDIERROR_SRC_NOTEXISTS = 3
- Source file is not exists.
- RDIERROR_SRC_NOTIMAGE = 2
- Source file is not image.
- RDIERROR_SRC_UNKNOWN = 16
- Unable to set source from this kind of image.
- RDIERROR_SRC_WEBP_ALPHA_NOTSUPPORTED = 1
- Not support alpha transparency WebP for current PHP version.
- RDIERROR_SRC_WEBP_ANIMATED_NOTSUPPORTED = 22
- Not support animated WebP for current PHP version (or current ImageMatick version).
- RDIERROR_WMI_NOTEXISTS = 11
- Watermark image not exists.
- RDIERROR_WMI_UNKNOWIMG = 10
- Unable to set watermark from this kind of image.
- RDIERROR_WMT_FONT_NOTEXISTS = 17
- Watermark text font file is not exists.
Properties
- $allow_resize_larger : bool
- Allow to set resize larger than source image.
- $destination_image_height : int
- $destination_image_object : resource|GdImage|null|false
- $destination_image_width : int
- $jpg_quality : int
- JPEG & WebP quality.
- $last_modified_image_height : int
- $last_modified_image_width : int
- $master_dim : string
- Master dimension.
- $png_quality : int
- PNG quality.
- $source_image_data : array<string|int, mixed>
- $source_image_ext : string
- $source_image_height : int
- $source_image_mime : string
- $source_image_object : resource|GdImage|null|false
- $source_image_path : string
- $source_image_type : string
- $source_image_width : int
- $status : bool
- Contain status of action methods.
- $status_msg : string
- Contain status error message of action methods.
- $statusCode : int
- Contain status code refer from class constants.
- $watermark_image_height : int
- $watermark_image_object : resource|GdImage|null|false
- $watermark_image_type : string
- $watermark_image_width : int
- $wmTextBottomPadding : int
- Add bottom padding to watermark text to let characters that long to the bottom can be displayed. Example p, g, ฤ, ฎ, etc.<br> This bottom padding should be different for each font size.
- $wmTextBoundingBoxYPadding : int
- Watermark text bounding box vertical (Y) padding.
- $destination_image_height : int
- $destination_image_object : resource|GdImage|null|false
- $destination_image_width : int
- $last_modified_image_height : int
- $last_modified_image_width : int
- $source_image_ext : string
- $source_image_height : int
- $source_image_mime : string
- $source_image_object : resource|GdImage|null|false
- $source_image_path : string
- $source_image_type : string
- $source_image_width : int
- $watermark_image_height : int
- $watermark_image_object : resource|GdImage|null|false
- $watermark_image_type : string
- $watermark_image_width : int
Methods
- __construct() : mixed
- Class constructor.
- __destruct() : mixed
- Class de-constructor.
- __get() : mixed
- Magic get
- __set() : mixed
- Magic set
- clear() : bool
- Clear and reset processed results to make it ready for new process while keep the original source.
- crop() : bool
- Crop the image.
- getImageFileData() : array<string|int, mixed>|false
- Get image file data such as width, height, mime type, extension.
- getImageSize() : array<string|int, mixed>
- Get source image size
- getStatic() : static
- Get this class as static call.
- resize() : bool
- Resize the image.
- resizeNoRatio() : bool
- Resize the image by ignoring aspect ratio.
- rotate() : bool
- Rotate the image.
- save() : bool
- Save the image to file.
- show() : mixed
- Show the image.
- watermarkImage() : bool
- Set the watermark image.
- watermarkText() : bool
- Set the watermark text.
- buildSourceImageData() : bool
- Build source image data
- 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.
- isClassSetup() : bool
- Verify that is class setup properly.
- isPreviousError() : bool
- Check is previous operation contain error?
- isResourceOrGDObject() : bool
- Check if image variable is resource of GD or is object of `\GdImage` (PHP 8.0) or not.
- normalizeDegree() : int|string
- Normalize degree.
- normalizeWidthHeight() : array<string|int, mixed>
- Convert width, height to integer and check if it is less than 0 then set to minimum value.
- 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.
- verifyQualityValue() : mixed
- Verify image save quality value.
- getImageColorAlpha() : mixed
- Get image color with alpha value (transparency).
- noOp() : mixed
- No operation.
- normalizeWatermarkOptions() : void
- Normalize watermark options.
- setupDestinationImageObjectWithSize() : bool
- Setup new canvas or "destination image object".
- setupSourceImageObject() : bool
- Setup source image object.
Constants
RDIERROR_CALCULATEFAILED_USE_RESIZENORATIO
Unable to calculated, please try to calculate on your own and use `resizeNoRatio()` instead.
public
mixed
RDIERROR_CALCULATEFAILED_USE_RESIZENORATIO
= 4
RDIERROR_CROP_UNKNOWNIMG
Unable to crop this kind of image.
since 3.1.4 There is no need to use this anymore.
public
mixed
RDIERROR_CROP_UNKNOWNIMG
= 5
RDIERROR_FLIP_NOTSUPPORTED
Not support flip for current PHP version. (PHP 5.5 or newer is required to use GD flip.)
public
mixed
RDIERROR_FLIP_NOTSUPPORTED
= 9
RDIERROR_FLIP_UNKNOWIMG
Unable to flip this kind of image.
since 3.1.4 There is no need to use this anymore.
public
mixed
RDIERROR_FLIP_UNKNOWIMG
= 8
RDIERROR_IMAGEMAGICK_NOTMEETREQUIREMENT
ImageMagick version does not meet requirement.
public
mixed
RDIERROR_IMAGEMAGICK_NOTMEETREQUIREMENT
= 21
RDIERROR_IMAGICK_NOTLOAD
Imagick extension was not loaded.
public
mixed
RDIERROR_IMAGICK_NOTLOAD
= 18
RDIERROR_IMAGICK_NOTMEETREQUIREMENT
Imagick version does not meet requirement.
public
mixed
RDIERROR_IMAGICK_NOTMEETREQUIREMENT
= 19
RDIERROR_IMAGICK_VERSIONUNKNOW
Could not verify Imagick version.
public
mixed
RDIERROR_IMAGICK_VERSIONUNKNOW
= 20
RDIERROR_RESIZE_UNKNOWIMG
Unable to resize this kind of image.
since 3.1.4 There is no need to use this anymore.
public
mixed
RDIERROR_RESIZE_UNKNOWIMG
= 6
RDIERROR_ROTATE_UNKNOWIMG
Unable to rotate this kind of image.
since 3.1.4 There is no need to use this anymore.
public
mixed
RDIERROR_ROTATE_UNKNOWIMG
= 7
RDIERROR_SAVE_FAILED
Failed to save an image.
public
mixed
RDIERROR_SAVE_FAILED
= 13
RDIERROR_SAVE_UNSUPPORT
Unable to save to this extension. or target file extension is not supported.
public
mixed
RDIERROR_SAVE_UNSUPPORT
= 12
RDIERROR_SHOW_FAILED
Failed to show an image to browser.
public
mixed
RDIERROR_SHOW_FAILED
= 15
RDIERROR_SHOW_UNSUPPORT
Unable to show image in this extension. File extension is not supported.
public
mixed
RDIERROR_SHOW_UNSUPPORT
= 14
RDIERROR_SRC_NOTEXISTS
Source file is not exists.
public
mixed
RDIERROR_SRC_NOTEXISTS
= 3
RDIERROR_SRC_NOTIMAGE
Source file is not image.
public
mixed
RDIERROR_SRC_NOTIMAGE
= 2
RDIERROR_SRC_UNKNOWN
Unable to set source from this kind of image.
public
mixed
RDIERROR_SRC_UNKNOWN
= 16
RDIERROR_SRC_WEBP_ALPHA_NOTSUPPORTED
Not support alpha transparency WebP for current PHP version.
public
mixed
RDIERROR_SRC_WEBP_ALPHA_NOTSUPPORTED
= 1
RDIERROR_SRC_WEBP_ANIMATED_NOTSUPPORTED
Not support animated WebP for current PHP version (or current ImageMatick version).
public
mixed
RDIERROR_SRC_WEBP_ANIMATED_NOTSUPPORTED
= 22
Tags
RDIERROR_WMI_NOTEXISTS
Watermark image not exists.
public
mixed
RDIERROR_WMI_NOTEXISTS
= 11
RDIERROR_WMI_UNKNOWIMG
Unable to set watermark from this kind of image.
public
mixed
RDIERROR_WMI_UNKNOWIMG
= 10
RDIERROR_WMT_FONT_NOTEXISTS
Watermark text font file is not exists.
public
mixed
RDIERROR_WMT_FONT_NOTEXISTS
= 17
Properties
$allow_resize_larger
Allow to set resize larger than source image.
public
bool
$allow_resize_larger
= false
Set to true to allow, false to disallow. Default is false.
$destination_image_height write-only
public
int
$destination_image_height
Destination image height. For internal use only.
$destination_image_object write-only
public
resource|GdImage|null|false
$destination_image_object
Image resource identifier
$destination_image_width write-only
public
int
$destination_image_width
Destination image width. For internal use only.
$jpg_quality
JPEG & WebP quality.
public
int
$jpg_quality
= 100
Quality from 0 (worst quality, smallest file) to 100 (best quality, biggest file). Default is 100.
$last_modified_image_height write-only
public
int
$last_modified_image_height
Last modified image height. For internal use only.
$last_modified_image_width write-only
public
int
$last_modified_image_width
Last modified image width. For internal use only.
$master_dim
Master dimension.
public
string
$master_dim
= 'auto'
Master dimension value is 'auto', 'width', or 'height'. Default is 'auto'.
$png_quality
PNG quality.
public
int
$png_quality
= 0
Compression level from 0 (no compression) to 9. Default is 0.
$source_image_data
public
array<string|int, mixed>
$source_image_data
Source image data.
Tags
$source_image_ext write-only
public
string
$source_image_ext
Source image file extension. For internal use only.
$source_image_height write-only
public
int
$source_image_height
Source image height. For internal use only.
$source_image_mime write-only
public
string
$source_image_mime
Source image mime type. Example image/jpeg. For internal use only.
$source_image_object write-only
public
resource|GdImage|null|false
$source_image_object
Image resource identifier
$source_image_path write-only
public
string
$source_image_path
Real full path to source image file. For internal use only.
$source_image_type write-only
public
string
$source_image_type
Source image type. Use with PHP predefined constants IMAGETYPE_XXX only. For internal use only.
$source_image_width write-only
public
int
$source_image_width
Source image width. For internal use only.
$status
Contain status of action methods.
public
bool
$status
= false
Return false if there is something error.
$status_msg
Contain status error message of action methods.
public
string
$status_msg
= null
Return error message. Default is null.
$statusCode
Contain status code refer from class constants.
public
int
$statusCode
= null
Return status code. See class constants. Default is null.
$watermark_image_height write-only
public
int
$watermark_image_height
Watermark image height. For internal use only.
$watermark_image_object write-only
public
resource|GdImage|null|false
$watermark_image_object
Image resource identifier for watermark image.
$watermark_image_type write-only
public
string
$watermark_image_type
Watermark image type. Use with PHP predefined constants IMAGETYPE_XXX only. For internal use only.
$watermark_image_width write-only
public
int
$watermark_image_width
Watermark image width. For internal use only.
$wmTextBottomPadding
Add bottom padding to watermark text to let characters that long to the bottom can be displayed. Example p, g, ฤ, ฎ, etc.<br> This bottom padding should be different for each font size.
public
int
$wmTextBottomPadding
= 5
Set the number of pixels to add to watermark text at the bottom. Default is 5, previous version was 5.
$wmTextBoundingBoxYPadding
Watermark text bounding box vertical (Y) padding.
public
int
$wmTextBoundingBoxYPadding
= 0
Set the number of watermark text bounding box padding. Default is 0.
$destination_image_height
protected
int
$destination_image_height
Destination image height.
$destination_image_object
protected
resource|GdImage|null|false
$destination_image_object
= null
Image resource identifier
$destination_image_width
protected
int
$destination_image_width
Destination image width.
$last_modified_image_height
protected
int
$last_modified_image_height
Last modified image height.
$last_modified_image_width
protected
int
$last_modified_image_width
Last modified image width.
$source_image_ext
protected
string
$source_image_ext
Source image file extension.
$source_image_height
protected
int
$source_image_height
Source image height.
$source_image_mime
protected
string
$source_image_mime
Source image mime type. Example image/jpeg.
$source_image_object
protected
resource|GdImage|null|false
$source_image_object
= null
Image resource identifier
$source_image_path
protected
string
$source_image_path
= ''
Real full path to source image file.
$source_image_type
protected
string
$source_image_type
Source image type. Use with PHP predefined constants IMAGETYPE_XXX only.
Tags
$source_image_width
protected
int
$source_image_width
Source image width.
$watermark_image_height
protected
int
$watermark_image_height
Watermark image height.
$watermark_image_object
protected
resource|GdImage|null|false
$watermark_image_object
= null
Image resource identifier for watermark image.
$watermark_image_type
protected
string
$watermark_image_type
Watermark image type. Use with PHP predefined constants IMAGETYPE_XXX only.
Tags
$watermark_image_width
protected
int
$watermark_image_width
Watermark image width.
Methods
__construct()
Class constructor.
public
__construct(mixed $source_image_path) : mixed
Parameters
- $source_image_path : mixed
-
Path to source image file.
__destruct()
Class de-constructor.
public
__destruct() : mixed
__get()
Magic get
public
__get(string $name) : mixed
Parameters
- $name : string
__set()
Magic set
public
__set(string $name, mixed $value) : mixed
Parameters
- $name : string
- $value : mixed
clear()
Clear and reset processed results to make it ready for new process while keep the original source.
public
clear() : bool
Return values
bool —Return true on successfully cleared.
crop()
Crop the image.
public
crop(mixed $width, mixed $height[, mixed $start_x = '0' ][, mixed $start_y = '0' ][, mixed $fill = 'transparent' ]) : bool
Parameters
- $width : mixed
-
Image width of cropping image. Size in pixels.
- $height : mixed
-
Image height of cropping image. Size in pixels.
- $start_x : mixed = '0'
-
Position to begin in x axis. The value is integer or 'center' for automatically calculate center.
- $start_y : mixed = '0'
-
Position to begin in y axis. The value is integer or 'middle' for automatically calculate middle.
- $fill : mixed = 'transparent'
-
Color of background that will be filled in case that image has transparent in it. The value is transparent, white, black (for gif, png, webp).
Return values
bool —Return true on success, false on failed. Call to status_msg property to see the details on failure.
getImageFileData()
Get image file data such as width, height, mime type, extension.
public
getImageFileData(string $imagePath) : array<string|int, mixed>|false
This will be use getimagesize() function if supported, something else as backup.
Parameters
- $imagePath : string
-
Full path to image file.
Tags
Return values
array<string|int, mixed>|false —Return array:
index 0 Image width.
index 1 Image height.
index 2 Image type constant. See more at https://www.php.net/manual/en/image.constants.php
mime key is mime type.
ext key is file extension with dot (.ext).
Other array keys are optional, it can be omit.
Return false on failure.
getImageSize()
Get source image size
public
getImageSize() : array<string|int, mixed>
Return values
array<string|int, mixed> —Return array of image size with 'width' and 'height' in array key.
getStatic()
Get this class as static call.
public
getStatic() : static
Return values
staticresize()
Resize the image.
public
resize(mixed $width, mixed $height) : bool
Parameters
- $width : mixed
-
Image width that image will be resize to.
- $height : mixed
-
Image height that image will be resize to.
Return values
bool —Return true on success, false on failed. Call to status_msg property to see the details on failure.
resizeNoRatio()
Resize the image by ignoring aspect ratio.
public
resizeNoRatio(mixed $width, mixed $height) : bool
Parameters
- $width : mixed
-
Image width that image will be resize to.
- $height : mixed
-
Image height that image will be resize to.
Return values
bool —Return true on success, false on failed. Call to status_msg property to see the details on failure.
rotate()
Rotate the image.
public
rotate([mixed $degree = 90 ]) : bool
Parameters
- $degree : mixed = 90
-
Degree of rotation (0, 90, 180, 270). For php >= 5.5, you can use 'hor', 'vrt', 'horvrt' as degree to flip the image.
Return values
bool —Return true on success, false on failed. Call to status_msg property to see the details on failure.
save()
Save the image to file.
public
save(mixed $file_name) : bool
Parameters
- $file_name : mixed
-
Path to save image to. Please including file extension.
Return values
bool —Return true on success, false on failed. Call to status_msg property to see the details on failure.
show()
Show the image.
public
show([mixed $file_ext = '' ]) : mixed
Parameters
- $file_ext : mixed = ''
-
The file extension that this image will be display as.
Return values
mixed —Show image content, return false on failed. Call to status_msg property to see the details on failure.
watermarkImage()
Set the watermark image.
public
watermarkImage(mixed $wm_img_path[, mixed $wm_img_start_x = 0 ][, mixed $wm_img_start_y = 0 ][, array<string|int, mixed> $options = [] ]) : bool
Parameters
- $wm_img_path : mixed
-
Full path of watermark image file
- $wm_img_start_x : mixed = 0
-
Position to begin in x axis. The value is integer or 'left', 'center', 'right'.
- $wm_img_start_y : mixed = 0
-
Position to begin in y axis. The value is integer or 'top', 'middle', 'bottom'.
- $options : array<string|int, mixed> = []
-
The watermark options. (Since v3.1.3)
padding(int) Padding around watermark object. Use with left, right, bottom, top but not middle, center. See\Rundiz\Image\Traits\CalculationTrait::calculateWatermarkImageStartXY().
opacity(int) The image opacity value from 0 (full transparent) to 100 (no transparent).
Return values
bool —Return true on success, false on failure. Call to status_msg property to see the details on failure.
watermarkText()
Set the watermark text.
public
watermarkText(mixed $wm_txt_text, mixed $wm_txt_font_path[, mixed $wm_txt_start_x = 0 ][, mixed $wm_txt_start_y = 0 ][, mixed $wm_txt_font_size = 10 ][, mixed $wm_txt_font_color = 'white' ][, mixed $wm_txt_font_alpha = 60 ][, array<string|int, mixed> $options = [] ]) : bool
Parameters
- $wm_txt_text : mixed
-
Watermark text
- $wm_txt_font_path : mixed
-
'True Type Font' path
- $wm_txt_start_x : mixed = 0
-
Position to begin in x axis. The value is integer or 'left', 'center', 'right'.
- $wm_txt_start_y : mixed = 0
-
Position to begin in x axis. The value is integer or 'top', 'middle', 'bottom'.
- $wm_txt_font_size : mixed = 10
-
Font size
- $wm_txt_font_color : mixed = 'white'
-
Font color. ('black', 'white', 'red', 'green', 'blue', 'yellow', 'cyan', 'magenta')
- $wm_txt_font_alpha : mixed = 60
-
Text transparency value from 0 (no transparent) to 127 (full transparent).
- $options : array<string|int, mixed> = []
-
The watermark text options. (Since v.3.1.0)
fillBackground(bool) Set totrueto fill background color for text bounding box. Default isfalseto use transparent.
backgroundColor(string) The background color to fill for text bounding box. Available values are 'black', 'white', 'red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'debug'.
backgroundAlpha(int) The background transparency value from 0 (no transparent) to 127 (full transparent). Default is 70.padding(int) (Since v3.1.3) Padding around watermark text. Use with left, right, bottom, top but not middle, center.
Return values
bool —Return true on success, false on failed. Call to status_msg property to see the details on failure.
buildSourceImageData()
Build source image data
protected
buildSourceImageData(string $source_image_path) : bool
Parameters
- $source_image_path : string
-
Path to source image file.
Return values
bool —Return true on success, false on failure. Call to statusCode or status_msg property to see the details on failure.
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
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
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".
isClassSetup()
Verify that is class setup properly.
protected
isClassSetup() : bool
If image source was not found then it will not setup properly.
Return values
bool —Return true on success, return false on failed.
isPreviousError()
Check is previous operation contain error?
protected
isPreviousError() : bool
Return values
bool —Return true if there is some error, false if there is not.
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
\GdImagevariable to check.
Tags
Return values
bool —Return true if it is resource or instance of \GdImage, return false if it is not.
normalizeDegree()
Normalize degree.
protected
normalizeDegree(int|string $degree) : int|string
If degree is allowed string then it will be return as-is. If degree is number then it will be convert to integer.
Parameters
- $degree : int|string
-
The degree.
Return values
int|string —Return converted degree.
normalizeWidthHeight()
Convert width, height to integer and check if it is less than 0 then set to minimum value.
protected
normalizeWidthHeight(int $width, int $height[, int|false $minWidth = 100 ][, int|false $minHeight = 100 ]) : array<string|int, mixed>
Parameters
- $width : int
-
Width
- $height : int
-
Height
- $minWidth : int|false = 100
-
Minimum that width must not less than 0. Set to
falseto not check it. Default is 100. - $minHeight : int|false = 100
-
Minimum that height must not less than 0. Set to
falseto not check it. Default is 100.
Return values
array<string|int, mixed> —Return 2D array where first index is width, second index is height.
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
setStatusSuccess()
Set status as success and remove error message, error code.
protected
setStatusSuccess() : mixed
Tags
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_XXXby PHP. This value may have got fromgetImageFileData()method.
Tags
Return values
GdImage|resource|false —Return resource or \GdImage (for PHP 8.0+) on success, false on failure.
verifyQualityValue()
Verify image save quality value.
protected
verifyQualityValue() : mixed
Tags
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
noOp()
No operation.
private
noOp() : mixed
This will be create new image object that has transparency and copy source image to it.
Tags
normalizeWatermarkOptions()
Normalize watermark options.
private
normalizeWatermarkOptions(array<string|int, mixed> &$options) : void
Parameters
- $options : array<string|int, mixed>
-
The watermark options to be altered.
Tags
setupDestinationImageObjectWithSize()
Setup new canvas or "destination image object".
private
setupDestinationImageObjectWithSize(int $width, int $height) : bool
Set in width and height for use with resize, crop.
Parameters
- $width : int
-
Destination image object width.
- $height : int
-
Destination image object height.
Return values
bool —Return true on success, false on failure.
setupSourceImageObject()
Setup source image object.
private
setupSourceImageObject() : bool
In case that this is first process, it will be create image object (or resource in older version of PHP) from image file.
Otherwise, it will be chaining image object from previous destination (or previous process).
Return values
bool —Return true on success, false on failure.