mirror of
https://codeberg.org/vlw/labylib-chattycape.git
synced 2025-09-14 00:23:41 +02:00
Release 1.0.0 Added default texture render backend inside 'backend/' Removed some debugging states from 'start.py' Tags can now use the full cape size for more flexibility. Updated tag textures for 'us.mineplex.com' to support this.
44 lines
No EOL
940 B
PHP
44 lines
No EOL
940 B
PHP
<?php
|
|
|
|
// Add horizontally centered text at x,y
|
|
class TextLayer {
|
|
|
|
public function __construct($text,$font,$size) {
|
|
$this->text = $text;
|
|
$this->font = $font;
|
|
|
|
$this->size = $this->scaleFont($text,$size);
|
|
$this->setFontPath();
|
|
}
|
|
|
|
// Prevent default GD font lookup path from being used
|
|
private function setFontPath() {
|
|
putenv("GDFONTPATH=".realpath("./".$this->font));
|
|
}
|
|
|
|
// Calculate scaled front size from max-width
|
|
private function scaleFont($text,$baseline) {
|
|
$len = strlen($this->text);
|
|
|
|
$log = $len / 0.6;
|
|
$size = $baseline - $log;
|
|
|
|
return $size;
|
|
}
|
|
|
|
// Center text
|
|
private function offsetX($x) {
|
|
$len = strlen($this->text);
|
|
|
|
$offset = $x - ($len * ($this->size / 2.2));
|
|
|
|
return $offset;
|
|
}
|
|
|
|
// Image resource, x, y
|
|
public function textcopy($image,$x,$y,$color) {
|
|
imagettftext($image,$this->size,0,$this->offsetX($x),$y,$color,"font",$this->text);
|
|
return true;
|
|
}
|
|
|
|
} |