Documentation

SimpleImageLib extends SimpleImage
in package

A PHP class that makes working with images as simple as possible.

Table of Contents

ERR_AVIF_NOT_ENABLED  = 12
ERR_FILE_NOT_FOUND  = 1
ERR_FONT_FILE  = 2
ERR_FREETYPE_NOT_ENABLED  = 3
ERR_GD_NOT_ENABLED  = 4
ERR_INVALID_COLOR  = 5
ERR_INVALID_DATA_URI  = 6
ERR_INVALID_FLAG  = 12
ERR_INVALID_IMAGE  = 7
ERR_LIB_NOT_LOADED  = 8
ERR_UNSUPPORTED_FORMAT  = 9
ERR_WEBP_NOT_ENABLED  = 10
ERR_WRITE  = 11
$exif  : mixed
$image  : mixed
$mimeType  : mixed
__construct()  : mixed
Creates a new SimpleImage object.
__destruct()  : mixed
Destroys the image resource.
adjustColor()  : array<string|int, int>
Adjusts a color by increasing/decreasing red/green/blue/alpha values independently.
arc()  : SimpleImage
Draws an arc.
autoOrient()  : SimpleImage
Rotates an image so the orientation will be correct based on its exif data. It is safe to call this method on images that don't have exif data (no changes will be made).
bestFit()  : SimpleImage
Proportionally resize the image to fit inside a specific width and height.
blur()  : SimpleImage
Applies the blur filter.
border()  : SimpleImage
Draws a border around the image.
brighten()  : SimpleImage
Applies the brightness filter to brighten the image.
colorize()  : SimpleImage
Applies the colorize filter.
contrast()  : SimpleImage
Applies the contrast filter.
crop()  : SimpleImage
Crop the image.
darken()  : SimpleImage
Applies the brightness filter to darken the image.
darkenColor()  : array<string|int, int>
Darkens a color.
desaturate()  : SimpleImage
Applies the desaturate (grayscale) filter.
dot()  : SimpleImage
Draws a single pixel dot.
duotone()  : SimpleImage
Applies a duotone filter to the image.
edgeDetect()  : SimpleImage
Applies the edge detect filter.
ellipse()  : SimpleImage
Draws an ellipse.
emboss()  : SimpleImage
Applies the emboss filter.
extractColors()  : array<string|int, int>
Extracts colors from an image like a human would do.™ This method requires the third-party library \League\ColorExtractor. If you're using Composer, it will be installed for you automatically.
fill()  : SimpleImage
Fills the image with a solid color.
fitToHeight()  : SimpleImage
Proportionally resize the image to a specific height.
fitToWidth()  : SimpleImage
Proportionally resize the image to a specific width.
flip()  : SimpleImage
Flip the image horizontally or vertically.
fromDataUri()  : SimpleImage
Loads an image from a data URI.
fromFile()  : SimpleImage
Loads an image from a file.
fromNew()  : SimpleImage
Creates a new image.
fromString()  : SimpleImage
Creates a new image from a string.
getAspectRatio()  : float
Gets the image's current aspect ratio.
getColorAt()  : array<string|int, int>
Gets the RGBA value of a single pixel.
getExif()  : array<string|int, mixed>|null
Gets the image's exif data.
getFlag()  : bool|null
Get flag value.
getHeight()  : int
Gets the image's current height.
getMimeType()  : string
Gets the mime type of the loaded image.
getOrientation()  : string
Gets the image's current orientation.
getResolution()  : mixed
Gets the resolution of the image
getWidth()  : int
Gets the image's current width.
invert()  : SimpleImage
Inverts the image's colors.
lightenColor()  : array<string|int, int>
Lightens a color.
line()  : SimpleImage
Draws a line.
maxColors()  : SimpleImage
Reduces the image to a maximum number of colors.
normalizeColor()  : array<string|int, mixed>
Normalizes a hex or array color value to a well-formatted RGBA array.
opacity()  : SimpleImage
Changes the image's opacity level.
overlay()  : SimpleImage
Place an image on top of the current image.
pixelate()  : SimpleImage
Applies the pixelate filter.
polygon()  : SimpleImage
Draws a polygon.
rectangle()  : SimpleImage
Draws a rectangle.
resize()  : SimpleImage
Resize an image to the specified dimensions. If only one dimension is specified, the image will be resized proportionally.
resolution()  : SimpleImage
Sets an image's resolution, as per https://www.php.net/manual/en/function.imageresolution.php
rotate()  : SimpleImage
Rotates the image.
roundedRectangle()  : SimpleImage
Draws a rounded rectangle.
sepia()  : SimpleImage
Simulates a sepia effect by desaturating the image and applying a sepia tone.
setFlag()  : mixed
Set flag value.
sharpen()  : SimpleImage
Sharpens the image.
sketch()  : SimpleImage
Applies the mean remove filter to produce a sketch effect.
text()  : SimpleImage
Adds text to the image.
textBox()  : SimpleImage
Adds text with a line break to the image.
thumbnail()  : SimpleImage
Creates a thumbnail image. This function attempts to get the image as close to the provided dimensions as possible, then crops the remaining overflow to force the desired size. Useful for generating thumbnail images.
toDataUri()  : string
Generates a data URI.
toDownload()  : SimpleImage
Forces the image to be downloaded to the clients machine. Must be called before any output is sent to the screen.
toFile()  : SimpleImage
Writes the image to a file.
toScreen()  : SimpleImage
Outputs the image to the screen. Must be called before any output is sent to the screen.
toString()  : string
Generates an image string.
allocateColor()  : int
Converts a "friendly color" into a color identifier for use with GD's image functions.
generate()  : array<string|int, mixed>
Generates an image.
imageCopyMergeAlpha()  : bool
Same as PHP's imagecopymerge, but works with transparent images. Used internally for overlay.
keepWithin()  : int|float
Ensures a numeric value is always within the min and max range.
excludeInsideColor()  : mixed
Exclude inside color.
textSeparateLines()  : array<string|int, mixed>
Receives a text and breaks into LINES.
textSeparateWords()  : array<string|int, mixed>
Receives a text and breaks into WORD / SPACE / NEW LINE.

Constants

ERR_FILE_NOT_FOUND

public mixed ERR_FILE_NOT_FOUND = 1

ERR_FREETYPE_NOT_ENABLED

public mixed ERR_FREETYPE_NOT_ENABLED = 3

ERR_GD_NOT_ENABLED

public mixed ERR_GD_NOT_ENABLED = 4

ERR_INVALID_COLOR

public mixed ERR_INVALID_COLOR = 5

ERR_INVALID_DATA_URI

public mixed ERR_INVALID_DATA_URI = 6

ERR_INVALID_IMAGE

public mixed ERR_INVALID_IMAGE = 7

ERR_LIB_NOT_LOADED

public mixed ERR_LIB_NOT_LOADED = 8

ERR_UNSUPPORTED_FORMAT

public mixed ERR_UNSUPPORTED_FORMAT = 9

ERR_WEBP_NOT_ENABLED

public mixed ERR_WEBP_NOT_ENABLED = 10

Properties

Methods

__construct()

Creates a new SimpleImage object.

public __construct([string $image = '' ][, array<string|int, mixed> $flags = [] ]) : mixed
Parameters
$image : string = ''

An image file or a data URI to load.

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

Optional override of default flags.

Tags
throws
Exception

Thrown if the GD library is not found; file|URI or image data is invalid.

Return values
mixed

__destruct()

Destroys the image resource.

public __destruct() : mixed
Return values
mixed

adjustColor()

Adjusts a color by increasing/decreasing red/green/blue/alpha values independently.

public static adjustColor(string|array<string|int, mixed> $color, int $red, int $green, int $blue, int $alpha) : array<string|int, int>
Parameters
$color : string|array<string|int, mixed>

The color to adjust.

$red : int

Red adjustment (-255 - 255).

$green : int

Green adjustment (-255 - 255).

$blue : int

Blue adjustment (-255 - 255).

$alpha : int

Alpha adjustment (-1 - 1).

Return values
array<string|int, int>

An RGBA color array.

arc()

Draws an arc.

public arc(int $x, int $y, int $width, int $height, int $start, int $end, string|array<string|int, mixed> $color[, int|string $thickness = 1 ]) : SimpleImage
Parameters
$x : int

The x coordinate of the arc's center.

$y : int

The y coordinate of the arc's center.

$width : int

The width of the arc.

$height : int

The height of the arc.

$start : int

The start of the arc in degrees.

$end : int

The end of the arc in degrees.

$color : string|array<string|int, mixed>

The arc color.

$thickness : int|string = 1

Line thickness in pixels or 'filled' (default 1).

Return values
SimpleImage

autoOrient()

Rotates an image so the orientation will be correct based on its exif data. It is safe to call this method on images that don't have exif data (no changes will be made).

public autoOrient() : SimpleImage
Return values
SimpleImage

bestFit()

Proportionally resize the image to fit inside a specific width and height.

public bestFit(int $maxWidth, int $maxHeight) : SimpleImage
Parameters
$maxWidth : int

The maximum width the image can be.

$maxHeight : int

The maximum height the image can be.

Return values
SimpleImage

blur()

Applies the blur filter.

public blur([string $type = 'selective' ][, number $passes = 1 ]) : SimpleImage
Parameters
$type : string = 'selective'

The blur algorithm to use: 'selective', 'gaussian' (default 'gaussian').

$passes : number = 1

The number of time to apply the filter, enhancing the effect (default 1).

Return values
SimpleImage

border()

Draws a border around the image.

public border(string|array<string|int, mixed> $color[, int $thickness = 1 ]) : SimpleImage
Parameters
$color : string|array<string|int, mixed>

The border color.

$thickness : int = 1

The thickness of the border (default 1).

Return values
SimpleImage

brighten()

Applies the brightness filter to brighten the image.

public brighten(int $percentage) : SimpleImage
Parameters
$percentage : int

Percentage to brighten the image (0 - 100).

Return values
SimpleImage

colorize()

Applies the colorize filter.

public colorize(string|array<string|int, mixed> $color) : SimpleImage
Parameters
$color : string|array<string|int, mixed>

The filter color.

Return values
SimpleImage

contrast()

Applies the contrast filter.

public contrast(int $percentage) : SimpleImage
Parameters
$percentage : int

Percentage to adjust (-100 - 100).

Return values
SimpleImage

crop()

Crop the image.

public crop(int|float $x1, int|float $y1, int|float $x2, int|float $y2) : SimpleImage
Parameters
$x1 : int|float

Top left x coordinate.

$y1 : int|float

Top left y coordinate.

$x2 : int|float

Bottom right x coordinate.

$y2 : int|float

Bottom right x coordinate.

Return values
SimpleImage

darken()

Applies the brightness filter to darken the image.

public darken(int $percentage) : SimpleImage
Parameters
$percentage : int

Percentage to darken the image (0 - 100).

Return values
SimpleImage

darkenColor()

Darkens a color.

public static darkenColor(string|array<string|int, mixed> $color, int $amount) : array<string|int, int>
Parameters
$color : string|array<string|int, mixed>

The color to darken.

$amount : int

Amount to darken (0 - 255).

Return values
array<string|int, int>

An RGBA color array.

dot()

Draws a single pixel dot.

public dot(int $x, int $y, string|array<string|int, mixed> $color) : SimpleImage
Parameters
$x : int

The x coordinate of the dot.

$y : int

The y coordinate of the dot.

$color : string|array<string|int, mixed>

The dot color.

Return values
SimpleImage

duotone()

Applies a duotone filter to the image.

public duotone(string|array<string|int, mixed> $lightColor, string|array<string|int, mixed> $darkColor) : SimpleImage
Parameters
$lightColor : string|array<string|int, mixed>

The lightest color in the duotone.

$darkColor : string|array<string|int, mixed>

The darkest color in the duotone.

Return values
SimpleImage

ellipse()

Draws an ellipse.

public ellipse(int $x, int $y, int $width, int $height, string|array<string|int, mixed> $color[, int|array<string|int, mixed> $thickness = 1 ]) : SimpleImage
Parameters
$x : int

The x coordinate of the center.

$y : int

The y coordinate of the center.

$width : int

The ellipse width.

$height : int

The ellipse height.

$color : string|array<string|int, mixed>

The ellipse color.

$thickness : int|array<string|int, mixed> = 1

Line thickness in pixels or 'filled' (default 1).

Return values
SimpleImage

extractColors()

Extracts colors from an image like a human would do.™ This method requires the third-party library \League\ColorExtractor. If you're using Composer, it will be installed for you automatically.

public extractColors([int $count = 5 ][, string|array<string|int, mixed> $backgroundColor = null ]) : array<string|int, int>
Parameters
$count : int = 5

The max number of colors to extract (default 5).

$backgroundColor : string|array<string|int, mixed> = null

By default any pixel with alpha value greater than zero will be discarded. This is because transparent colors are not perceived as is. For example, fully transparent black would be seen white on a white background. So if you want to take transparency into account, you have to specify a default background color.

Tags
throws
Exception

Thrown if library \League\ColorExtractor is missing.

Return values
array<string|int, int>

An array of RGBA colors arrays.

fill()

Fills the image with a solid color.

public fill(string|array<string|int, mixed> $color) : SimpleImage
Parameters
$color : string|array<string|int, mixed>

The fill color.

Return values
SimpleImage

fitToHeight()

Proportionally resize the image to a specific height.

public fitToHeight(int $height) : SimpleImage
Parameters
$height : int
Tags
deprecated

This method was deprecated in version 3.2.2 and will be removed in version 4.0. Please use resize(null, $height) instead.

Return values
SimpleImage

fitToWidth()

Proportionally resize the image to a specific width.

public fitToWidth(int $width) : SimpleImage
Parameters
$width : int

The width to resize the image to.

Tags
deprecated

This method was deprecated in version 3.2.2 and will be removed in version 4.0. Please use resize(null, $height) instead.

Return values
SimpleImage

flip()

Flip the image horizontally or vertically.

public flip(string $direction) : SimpleImage
Parameters
$direction : string

The direction to flip: x|y|both.

Return values
SimpleImage

fromDataUri()

Loads an image from a data URI.

public fromDataUri(string $uri) : SimpleImage
Parameters
$uri : string

A data URI.

Tags
throws
Exception

Thrown if URI or image data is invalid.

Return values
SimpleImage

fromFile()

Loads an image from a file.

public fromFile(string $file) : SimpleImage
Parameters
$file : string

The image file to load.

Tags
throws
Exception

Thrown if file or image data is invalid.

Return values
SimpleImage

fromNew()

Creates a new image.

public fromNew(int $width, int $height[, string|array<string|int, mixed> $color = 'transparent' ]) : SimpleImage
Parameters
$width : int

The width of the image.

$height : int

The height of the image.

$color : string|array<string|int, mixed> = 'transparent'

Optional fill color for the new image (default 'transparent').

Return values
SimpleImage

fromString()

Creates a new image from a string.

public fromString(string $string) : SimpleImage
Parameters
$string : string

The raw image data as a string.

Tags
example

$string = file_get_contents('image.jpg');

Return values
SimpleImage

getAspectRatio()

Gets the image's current aspect ratio.

public getAspectRatio() : float
Return values
float

Returns the aspect ratio as a float.

getColorAt()

Gets the RGBA value of a single pixel.

public getColorAt(int $x, int $y) : array<string|int, int>
Parameters
$x : int

The horizontal position of the pixel.

$y : int

The vertical position of the pixel.

Return values
array<string|int, int>

An RGBA color array or false if the x/y position is off the canvas.

getExif()

Gets the image's exif data.

public getExif() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

Returns an array of exif data or null if no data is available.

getFlag()

Get flag value.

public getFlag(string $flag) : bool|null
Parameters
$flag : string

Name of the flag to get.

Return values
bool|null

getHeight()

Gets the image's current height.

public getHeight() : int
Return values
int

getMimeType()

Gets the mime type of the loaded image.

public getMimeType() : string
Return values
string

getOrientation()

Gets the image's current orientation.

public getOrientation() : string
Return values
string

One of the values: 'landscape', 'portrait', or 'square'

getResolution()

Gets the resolution of the image

public getResolution() : mixed
Return values
mixed

The resolution as an array of integers: [96, 96]

getWidth()

Gets the image's current width.

public getWidth() : int
Return values
int

lightenColor()

Lightens a color.

public static lightenColor(string|array<string|int, mixed> $color, int $amount) : array<string|int, int>
Parameters
$color : string|array<string|int, mixed>

The color to lighten.

$amount : int

Amount to lighten (0 - 255).

Return values
array<string|int, int>

An RGBA color array.

line()

Draws a line.

public line(int $x1, int $y1, int $x2, int $y2, string|array<string|int, mixed> $color[, int $thickness = 1 ]) : SimpleImage
Parameters
$x1 : int

The x coordinate for the first point.

$y1 : int

The y coordinate for the first point.

$x2 : int

The x coordinate for the second point.

$y2 : int

The y coordinate for the second point.

$color : string|array<string|int, mixed>

The line color.

$thickness : int = 1

The line thickness (default 1).

Return values
SimpleImage

maxColors()

Reduces the image to a maximum number of colors.

public maxColors(int $max[, bool $dither = true ]) : SimpleImage
Parameters
$max : int

The maximum number of colors to use.

$dither : bool = true

Whether or not to use a dithering effect (default true).

Return values
SimpleImage

normalizeColor()

Normalizes a hex or array color value to a well-formatted RGBA array.

public static normalizeColor(string|array<string|int, mixed> $color) : array<string|int, mixed>
Parameters
$color : string|array<string|int, mixed>

A CSS color name, hex string, or an array [red, green, blue, alpha]. You can pipe alpha transparency through hex strings and color names. For example: #fff|0.50 <-- 50% white red|0.25 <-- 25% red

Tags
throws
Exception

Thrown if color value is invalid.

Return values
array<string|int, mixed>

[red, green, blue, alpha].

opacity()

Changes the image's opacity level.

public opacity(float $opacity) : SimpleImage
Parameters
$opacity : float

The desired opacity level (0 - 1).

Return values
SimpleImage

overlay()

Place an image on top of the current image.

public overlay(string|SimpleImage $overlay[, string $anchor = 'center' ][, float $opacity = 1 ], int $xOffset, int $yOffset[, bool $calculateOffsetFromEdge = false ]) : SimpleImage
Parameters
$overlay : string|SimpleImage

The image to overlay. This can be a filename, a data URI, or a SimpleImage object.

$anchor : string = 'center'

The anchor point: 'center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right' (default 'center').

$opacity : float = 1

The opacity level of the overlay 0-1 (default 1).

$xOffset : int

Horizontal offset in pixels (default 0).

$yOffset : int

Vertical offset in pixels (default 0).

$calculateOffsetFromEdge : bool = false

Calculate Offset referring to the edges of the image (default false).

Return values
SimpleImage

pixelate()

Applies the pixelate filter.

public pixelate([int $size = 10 ]) : SimpleImage
Parameters
$size : int = 10

The size of the blocks in pixels (default 10).

Return values
SimpleImage

polygon()

Draws a polygon.

public polygon(array<string|int, mixed> $vertices, string|array<string|int, mixed> $color[, int|array<string|int, mixed> $thickness = 1 ]) : SimpleImage
Parameters
$vertices : array<string|int, mixed>

The polygon's vertices in an array of x/y arrays. Example: [ ['x' => x1, 'y' => y1], ['x' => x2, 'y' => y2], ['x' => xN, 'y' => yN] ]

$color : string|array<string|int, mixed>

The polygon color.

$thickness : int|array<string|int, mixed> = 1

Line thickness in pixels or 'filled' (default 1).

Return values
SimpleImage

rectangle()

Draws a rectangle.

public rectangle(int $x1, int $y1, int $x2, int $y2, string|array<string|int, mixed> $color[, int|array<string|int, mixed> $thickness = 1 ]) : SimpleImage
Parameters
$x1 : int

The upper left x coordinate.

$y1 : int

The upper left y coordinate.

$x2 : int

The bottom right x coordinate.

$y2 : int

The bottom right y coordinate.

$color : string|array<string|int, mixed>

The rectangle color.

$thickness : int|array<string|int, mixed> = 1

Line thickness in pixels or 'filled' (default 1).

Return values
SimpleImage

resize()

Resize an image to the specified dimensions. If only one dimension is specified, the image will be resized proportionally.

public resize([int $width = null ][, int $height = null ]) : SimpleImage
Parameters
$width : int = null

The new image width.

$height : int = null

The new image height.

Return values
SimpleImage

resolution()

Sets an image's resolution, as per https://www.php.net/manual/en/function.imageresolution.php

public resolution(int $res_x[, int $res_y = null ]) : SimpleImage
Parameters
$res_x : int

The horizontal resolution in DPI.

$res_y : int = null

The vertical resolution in DPI

Return values
SimpleImage

rotate()

Rotates the image.

public rotate(int $angle[, string|array<string|int, mixed> $backgroundColor = 'transparent' ]) : SimpleImage
Parameters
$angle : int

The angle of rotation (-360 - 360).

$backgroundColor : string|array<string|int, mixed> = 'transparent'

The background color to use for the uncovered zone area after rotation (default 'transparent').

Return values
SimpleImage

roundedRectangle()

Draws a rounded rectangle.

public roundedRectangle(int $x1, int $y1, int $x2, int $y2, int $radius, string|array<string|int, mixed> $color[, int|array<string|int, mixed> $thickness = 1 ]) : SimpleImage
Parameters
$x1 : int

The upper left x coordinate.

$y1 : int

The upper left y coordinate.

$x2 : int

The bottom right x coordinate.

$y2 : int

The bottom right y coordinate.

$radius : int

The border radius in pixels.

$color : string|array<string|int, mixed>

The rectangle color.

$thickness : int|array<string|int, mixed> = 1

Line thickness in pixels or 'filled' (default 1).

Return values
SimpleImage

setFlag()

Set flag value.

public setFlag(string $flag, bool $value) : mixed
Parameters
$flag : string

Name of the flag to set.

$value : bool

State of the flag.

Tags
throws
Exception

Thrown if flag does not exist (no default value).

Return values
mixed

sharpen()

Sharpens the image.

public sharpen([int $amount = 50 ]) : SimpleImage
Parameters
$amount : int = 50

Sharpening amount (default 50).

Return values
SimpleImage

text()

Adds text to the image.

public text(string $text, array<string|int, mixed> $options[, array<string|int, mixed> &$boundary = null ]) : SimpleImage
Parameters
$text : string

The desired text.

$options : array<string|int, mixed>

An array of options.

  • fontFile* (string) - The TrueType (or compatible) font file to use.
  • size (integer) - The size of the font in pixels (default 12).
  • color (string|array) - The text color (default black).
  • anchor (string) - The anchor point: 'center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right' (default 'center').
  • xOffset (integer) - The horizontal offset in pixels (default 0).
  • yOffset (integer) - The vertical offset in pixels (default 0).
  • shadow (array) - Text shadow params.
    • x* (integer) - Horizontal offset in pixels.
    • y* (integer) - Vertical offset in pixels.
    • color* (string|array) - The text shadow color.
  • $calculateOffsetFromEdge (bool) - Calculate offsets from the edge of the image (default false).
  • $baselineAlign (bool) - Align the text font with the baseline. (default true).
$boundary : array<string|int, mixed> = null

If passed, this variable will contain an array with coordinates that surround the text: [x1, y1, x2, y2, width, height]. This can be used for calculating the text's position after it gets added to the image.

Tags
throws
Exception
Return values
SimpleImage

textBox()

Adds text with a line break to the image.

public textBox(string $text, array<string|int, mixed> $options) : SimpleImage
Parameters
$text : string

The desired text.

$options : array<string|int, mixed>

An array of options.

  • fontFile* (string) - The TrueType (or compatible) font file to use.
  • size (integer) - The size of the font in pixels (default 12).
  • color (string|array) - The text color (default black).
  • anchor (string) - The anchor point: 'center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right' (default 'center').
  • xOffset (integer) - The horizontal offset in pixels (default 0). Has no effect when anchor is 'center'.
  • yOffset (integer) - The vertical offset in pixels (default 0). Has no effect when anchor is 'center'.
  • shadow (array) - Text shadow params.
    • x* (integer) - Horizontal offset in pixels.
    • y* (integer) - Vertical offset in pixels.
    • color* (string|array) - The text shadow color.
  • $calculateOffsetFromEdge (bool) - Calculate offsets from the edge of the image (default false).
  • width (int) - Width of text box (default image width).
  • align (string) - How to align text: 'left', 'right', 'center', 'justify' (default 'left').
  • leading (float) - Increase/decrease spacing between lines of text (default 0).
  • opacity (float) - The opacity level of the text 0-1 (default 1).
Tags
throws
Exception
Return values
SimpleImage

thumbnail()

Creates a thumbnail image. This function attempts to get the image as close to the provided dimensions as possible, then crops the remaining overflow to force the desired size. Useful for generating thumbnail images.

public thumbnail(int $width, int $height[, string $anchor = 'center' ]) : SimpleImage
Parameters
$width : int

The thumbnail width.

$height : int

The thumbnail height.

$anchor : string = 'center'

The anchor point: 'center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right' (default 'center').

Return values
SimpleImage

toDataUri()

Generates a data URI.

public toDataUri([string $mimeType = null ][, int $quality = 100 ]) : string
Parameters
$mimeType : string = null

The image format to output as a mime type (defaults to the original mime type).

$quality : int = 100

Image quality as a percentage (default 100).

Return values
string

Returns a string containing a data URI.

toDownload()

Forces the image to be downloaded to the clients machine. Must be called before any output is sent to the screen.

public toDownload(string $filename[, string $mimeType = null ][, int $quality = 100 ]) : SimpleImage
Parameters
$filename : string

The filename (without path) to send to the client (e.g. 'image.jpeg').

$mimeType : string = null

The image format to output as a mime type (defaults to the original mime type).

$quality : int = 100

Image quality as a percentage (default 100).

Return values
SimpleImage

toFile()

Writes the image to a file.

public toFile(string $file[, string $mimeType = null ][, int $quality = 100 ]) : SimpleImage
Parameters
$file : string

The image format to output as a mime type (defaults to the original mime type).

$mimeType : string = null

Image quality as a percentage (default 100).

$quality : int = 100

Image quality as a percentage (default 100).

Tags
throws
Exception

Thrown if failed write to file.

Return values
SimpleImage

toScreen()

Outputs the image to the screen. Must be called before any output is sent to the screen.

public toScreen([string $mimeType = null ][, int $quality = 100 ]) : SimpleImage
Parameters
$mimeType : string = null

The image format to output as a mime type (defaults to the original mime type).

$quality : int = 100

Image quality as a percentage (default 100).

Return values
SimpleImage

toString()

Generates an image string.

public toString([string $mimeType = null ][, int $quality = 100 ]) : string
Parameters
$mimeType : string = null

The image format to output as a mime type (defaults to the original mime type).

$quality : int = 100

Image quality as a percentage (default 100).

Return values
string

allocateColor()

Converts a "friendly color" into a color identifier for use with GD's image functions.

protected allocateColor(string|array<string|int, mixed> $color) : int
Parameters
$color : string|array<string|int, mixed>

The color to allocate.

Return values
int

generate()

Generates an image.

protected generate([string $mimeType = null ][, int $quality = 100 ]) : array<string|int, mixed>
Parameters
$mimeType : string = null

The image format to output as a mime type (defaults to the original mime type).

$quality : int = 100

Image quality as a percentage (default 100).

Tags
throws
Exception

Thrown when WEBP support is not enabled or unsupported format.

Return values
array<string|int, mixed>

Returns an array containing the image data and mime type ['data' => '', 'mimeType' => ''].

imageCopyMergeAlpha()

Same as PHP's imagecopymerge, but works with transparent images. Used internally for overlay.

protected static imageCopyMergeAlpha(resource $dstIm, resource $srcIm, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH, int $pct) : bool
Parameters
$dstIm : resource

Destination image link resource.

$srcIm : resource

Source image link resource.

$dstX : int

x-coordinate of destination point.

$dstY : int

y-coordinate of destination point.

$srcX : int

x-coordinate of source point.

$srcY : int

y-coordinate of source point.

$srcW : int

Source width.

$srcH : int

Source height.

$pct : int
Return values
bool

true if success.

keepWithin()

Ensures a numeric value is always within the min and max range.

protected static keepWithin(int|float $value, int|float $min, int|float $max) : int|float
Parameters
$value : int|float

A numeric value to test.

$min : int|float

The minimum allowed value.

$max : int|float

The maximum allowed value.

Return values
int|float

excludeInsideColor()

Exclude inside color.

private excludeInsideColor(number $x, number $y, string|array<string|int, mixed> $borderColor) : mixed

Used for roundedRectangle(), ellipse() and arc()

Parameters
$x : number

certer x of rectangle.

$y : number

certer y of rectangle.

$borderColor : string|array<string|int, mixed>

The color of border.

Return values
mixed

textSeparateLines()

Receives a text and breaks into LINES.

private textSeparateLines(int $text, string $fontFile, int $fontSize, int $maxWidth) : array<string|int, mixed>
Parameters
$text : int
$fontFile : string
$fontSize : int
$maxWidth : int
Return values
array<string|int, mixed>

textSeparateWords()

Receives a text and breaks into WORD / SPACE / NEW LINE.

private textSeparateWords(int $text) : array<string|int, mixed>
Parameters
$text : int
Return values
array<string|int, mixed>

Search results