php-gdlabel/src/Elements/StringElement.php

46 lines
1.1 KiB
PHP

<?php
namespace NoccyLabs\GdLabel\Elements;
use NoccyLabs\GdLabel\Element;
class StringElement extends Element
{
protected function draw($gd, int $x, int $y, int $width, int $height, array $params)
{
if (($bound = $this->getProp("bind-value"))) {
$value = array_key_exists($bound, $params)?$params[$bound]:"?{$bound}?";
} else {
$value = $this->getProp("value");
}
$value = \preg_replace_callback('/([åäöÅÄÖ]{1})/', function ($c) {
switch ($c) {
case 'å':
case 'ä':
return "a";
case 'ö':
return "o";
case 'Å':
case 'Ä':
return "A";
case 'Ö':
return "O";
}
}, $value);
$color = $this->getPropRgb("text-color");
$size = $this->getProp("text-size", 0) * 2;
$weight = $this->getProp("font-weight");
if ($weight == "bold") {
$size++;
}
imagestring($gd, $size, $x, $y, $value, $color);
}
}