DefaultText
extends AbstractTextLayer
in package
Default cover text layer
Tags
Table of Contents
- $colorMap : array<string|int, mixed>
- Mapping of color names to RGB values.
- render() : void
- Render the layer
- drawAuthor() : void
- Render author at bottom in wrapped, white text with black border
- drawText() : void
- Simulate outlined text
- drawTitle() : void
- Render title in wrapped, black text with white border
- getColor() : int|false
- Check and allocates color
- getHSBColor() : int
- Using HSB allows us to control the contrast while allowing randomness
- textHeight() : int
- Returns the height a string would render to
- textWidth() : int
- Returns the width a string would render to
Properties
$colorMap
Mapping of color names to RGB values.
protected
array<string|int, mixed>
$colorMap
= ['black' => [0, 0, 0], 'silver' => [192, 192, 192], 'gray' => [128, 128, 128], 'white' => [255, 255, 255], 'maroon' => [128, 0, 0], 'red' => [255, 0, 0], 'purple' => [128, 0, 128], 'fuchsia' => [255, 0, 255], 'green' => [0, 128, 0], 'lime' => [0, 255, 0], 'olive' => [128, 128, 0], 'yellow' => [255, 255, 0], 'navy' => [0, 0, 128], 'blue' => [0, 0, 255], 'teal' => [0, 128, 128], 'aqua' => [0, 255, 255]]
Methods
render()
Render the layer
public
render(resource $im, array<string|int, mixed> $details, object $settings) : void
Parameters
- $im : resource
-
Image resource to draw on
- $details : array<string|int, mixed>
-
Cover details array (with title/author/call_number)
- $settings : object
-
Settings object
Return values
void —drawAuthor()
Render author at bottom in wrapped, white text with black border
protected
drawAuthor(resource $im, object $settings, string $author) : void
Parameters
- $im : resource
-
Image resource to draw on
- $settings : object
-
Settings object
- $author : string
-
Author to write
Return values
void —drawText()
Simulate outlined text
protected
drawText(resource $im, object $settings, string $text, int $y, string $font, int $fontSize, int $mcolor[, int $scolor = false ][, string $align = null ]) : void
Parameters
- $im : resource
-
Active image resource
- $settings : object
-
Generator settings object
- $text : string
-
Text to render
- $y : int
-
Top position
- $font : string
-
Full path to font
- $fontSize : int
-
Size of the font
- $mcolor : int
-
Main text color
- $scolor : int = false
-
Secondary border color
- $align : string = null
-
'left','center','right'
Return values
void —drawTitle()
Render title in wrapped, black text with white border
protected
drawTitle(resource $im, object $settings, string $title, int $lineHeight) : void
Parameters
- $im : resource
-
Image resource to draw on
- $settings : object
-
Settings object
- $title : string
-
Title to write
- $lineHeight : int
-
Pixels we move down each line
Return values
void —getColor()
Check and allocates color
protected
getColor(resource $im, string $color) : int|false
Parameters
- $im : resource
-
Image resource being updated
- $color : string
-
Legal color name from HTML4
Return values
int|false —allocated color
getHSBColor()
Using HSB allows us to control the contrast while allowing randomness
protected
getHSBColor(resource $im, int $h, int $s, int $v) : int
Parameters
- $im : resource
-
Active image resource
- $h : int
-
Hue (0-255)
- $s : int
-
Saturation (0-255)
- $v : int
-
Lightness (0-255)
Return values
int —textHeight()
Returns the height a string would render to
protected
textHeight(string $text, string $font, string $size) : int
Parameters
- $text : string
-
Text to test
- $font : string
-
Full font path
- $size : string
-
Size of the font
Return values
int —textWidth()
Returns the width a string would render to
protected
textWidth(string $text, string $font, string $size) : int
Parameters
- $text : string
-
Text to test
- $font : string
-
Full font path
- $size : string
-
Size of the font