Sledgehammer Framework

TextGraphics extends Graphics
in package

A layer for advanced text rendering.

Uses CSS style options: "font: bold 14px Arial, sans-serif".

Table of Contents

$aspectRatio  : float
$defaultStyle  : string|array<string|int, mixed>
$fontFolders  : array<string|int, mixed>
$height  : int
$width  : int
$gd  : resource
$angle  : float
$color  : mixed
$fontFamily  : array<string|int, mixed>
$fontSize  : float
$fontStyle  : string
$fontWeight  : string
$lineHeight  : float
$text  : string
__call()  : mixed
Report that the $method doesn't exist.
__callStatic()  : mixed
Report that the $method doesn't exist.
__construct()  : mixed
__destruct()  : mixed
__get()  : mixed
Report that $property doesn't exist.
__set()  : mixed
Report that $property doesn't exist and set the property to the given $value.
__toString()  : string
The object is used as an string.
cropped()  : Graphics
Return a new Graphics object with the cropped contents.
fitInto()  : mixed
Change the fontSize to fit the text inside the given width & height.
flipped()  : Graphics
Return a new Graphics object with the contents flipped.
getHeaders()  : mixed
isDocument()  : true
This Component can not be nested inside another Component.
render()  : mixed
resized()  : Image
Returns a new Graphics object in the given size.
rotated()  : Graphics
Return a new Graphics object in te given rotation.
saveAs()  : mixed
Save the graphic as an image.
saveThumbnail()  : mixed
Create a thumbnail.
colorIndex()  : int
Resolve/Allocate palete index for the given $color.
createCanvas()  : resource
Create a transparent gd resource with full (white) alphachannel.
getAspectRatio()  : float
getHeight()  : int
getTextBounds()  : array<string|int, mixed>
Retrieve the bounds of the current text & style.
getWidth()  : int
rasterize()  : resource
Rasterize the layer to an GD resource.
rasterizeTo()  : mixed
Render the text onto the given $gd resource.
rasterizeTruecolor()  : resource
Rasterize the layer to a truecolor(32bit) GD resource.
getBuildinFontIndex()  : int
Geeft het interne font o.p.v. de $this->size Als $this->font een integer is, wordt deze gebruikt.
parseRule()  : string
Validates and corrects css rule values.
parseStyle()  : array<string|int, mixed>
Parse css rules into fontOptions.
resolveFont()  : array<string|int, mixed>|false
Doorzoek de fontmappen naar het opgegeven font.
useBuildinFont()  : bool
Geeft aan of er gebruik gemaakt moet worden van de build-in fonts.

Properties

$aspectRatio read-only

public float $aspectRatio

$defaultStyle

public static string|array<string|int, mixed> $defaultStyle = 'font: 13px/120% "DejaVu Sans", sans-serif'

Allows overriding the default font style.

$fontFolders

public static array<string|int, mixed> $fontFolders = [ '/usr/share/fonts/truetype/', // Linux (Ubuntu) '/usr/share/fonts/TTF/', // Linux (Arch) '/Library/Fonts/', // Mac OSX '/usr/X11/lib/X11/fonts/TTF/', // X11 'c:/windows/fonts/', ]

$fontFamily

private array<string|int, mixed> $fontFamily = ['sans-serif']

Font aam van het font ("Arial", "New Times Roman", etc) of 1 - 5 voor built-in fonts

$fontStyle

private string $fontStyle = 'normal'

normal|italic|oblique

$fontWeight

private string $fontWeight = 'normal'

normal|bold

Methods

__call()

Report that the $method doesn't exist.

public __call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string
$arguments : array<string|int, mixed>
Return values
mixed

__callStatic()

Report that the $method doesn't exist.

public static __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string
$arguments : array<string|int, mixed>
Return values
mixed

__construct()

public __construct(string $text[, string|array<string|int, mixed> $style = [] ]) : mixed
Parameters
$text : string
$style : string|array<string|int, mixed> = []

"font-weight: bold; color: red" or array('color' => 'red', 'font-weight' => 'bold')

Return values
mixed

__destruct()

public __destruct() : mixed
Return values
mixed

__get()

Report that $property doesn't exist.

public __get(string $property) : mixed
Parameters
$property : string
Return values
mixed

__set()

Report that $property doesn't exist and set the property to the given $value.

public __set(string $property, mixed $value) : mixed
Parameters
$property : string
$value : mixed
Return values
mixed

__toString()

The object is used as an string.

public __toString() : string
Return values
string

cropped()

Return a new Graphics object with the cropped contents.

public cropped(int $width, int $height[, int $offsetLeft = null ][, int $offsetTop = null ]) : Graphics

Resizes the canvas, but not the contents.

Parameters
$width : int

The new width

$height : int

The new height

$offsetLeft : int = null

Offset left (null: centered)

$offsetTop : int = null

Offset top (null: centered)

Return values
Graphics

fitInto()

Change the fontSize to fit the text inside the given width & height.

public fitInto(int $width, int $height) : mixed
Parameters
$width : int
$height : int
Return values
mixed

flipped()

Return a new Graphics object with the contents flipped.

public flipped([enum $mode = 'both' ]) : Graphics
Parameters
$mode : enum = 'both'

"horizontal" left <-> right, "vertical": up ^v down, "both": rotates 180deg

Return values
Graphics

getHeaders()

public getHeaders() : mixed
Return values
mixed

isDocument()

This Component can not be nested inside another Component.

public isDocument() : true
Return values
true

render()

public render() : mixed
Return values
mixed

resized()

Returns a new Graphics object in the given size.

public resized(int $width, int $height) : Image
Parameters
$width : int
$height : int
Return values
Image

rotated()

Return a new Graphics object in te given rotation.

public rotated(float $angle[, string $bgcolor = 'rgba(255,255,255,0)' ]) : Graphics
Parameters
$angle : float
$bgcolor : string = 'rgba(255,255,255,0)'
Return values
Graphics

saveAs()

Save the graphic as an image.

public saveAs(string $filename[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$filename : string
$options : array<string|int, mixed> = []
Return values
mixed

saveThumbnail()

Create a thumbnail.

public saveThumbnail(string $filename, int $width, int $height) : mixed
Parameters
$filename : string
$width : int
$height : int
Return values
mixed

colorIndex()

Resolve/Allocate palete index for the given $color.

protected colorIndex(string $color[,  $gd = null ]) : int
Parameters
$color : string

Allowed syntax: 'red' '#f00' '#ff0000' 'rgb(255, 0, 0)' 'rgba(255, 0, 0, 0.5)'

$gd : = null

(optional) GD resource

Return values
int

createCanvas()

Create a transparent gd resource with full (white) alphachannel.

protected createCanvas(int $width, int $height[, mixed $bgcolor = 'rgba(255,255,255,0)' ]) : resource
Parameters
$width : int
$height : int
$bgcolor : mixed = 'rgba(255,255,255,0)'
Return values
resource

gd

getAspectRatio()

protected getAspectRatio() : float
Return values
float

Aspect ratio

getHeight()

protected getHeight() : int
Return values
int

Height

getTextBounds()

Retrieve the bounds of the current text & style.

protected getTextBounds() : array<string|int, mixed>
Return values
array<string|int, mixed>

array( 'width' => ?, 'height' => ?, 'top' => ?, 'left' => ? );

getWidth()

protected getWidth() : int
Return values
int

Width

rasterize()

Rasterize the layer to an GD resource.

protected rasterize() : resource

Updates and returns the internal gd resource.

Return values
resource

gd

rasterizeTo()

Render the text onto the given $gd resource.

protected rasterizeTo(resource $gd, int $x, int $y) : mixed
Parameters
$gd : resource

resource

$x : int
$y : int
Return values
mixed

rasterizeTruecolor()

Rasterize the layer to a truecolor(32bit) GD resource.

protected rasterizeTruecolor() : resource

Updates and returns the internal gd resource.

Return values
resource

gd

getBuildinFontIndex()

Geeft het interne font o.p.v. de $this->size Als $this->font een integer is, wordt deze gebruikt.

private getBuildinFontIndex() : int
Return values
int

parseRule()

Validates and corrects css rule values.

private parseRule(string $property, string $value) : string
Parameters
$property : string

CSS property. "font-weight", etc

$value : string

Example: "bold"

Return values
string

parseStyle()

Parse css rules into fontOptions.

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

resolveFont()

Doorzoek de fontmappen naar het opgegeven font.

private resolveFont([mixed $familyIndex = null ]) : array<string|int, mixed>|false
Parameters
$familyIndex : mixed = null
Return values
array<string|int, mixed>|false

Geeft false als het font niet gevonden wordt.

useBuildinFont()

Geeft aan of er gebruik gemaakt moet worden van de build-in fonts.

private useBuildinFont() : bool
Return values
bool

Search results