labylib-chattycape/backend/classes/TextLayer.php
Victor Westerlund c2fa933b3a 1.0.0
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.
2020-11-18 14:06:08 +01:00

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;
}
}