fix: Определения типов

This commit is contained in:
origami11@yandex.ru 2025-10-01 12:37:39 +03:00
parent 9f6fd74b17
commit dd74a97894
28 changed files with 334 additions and 249 deletions

View file

@ -41,9 +41,8 @@ class TemplateImage
public $resource;
public $filename;
function __construct ($template = null)
function __construct (?string $template = null)
{
// assert(is_string($src));
if ($template) {
$this->data = $template;
}
@ -52,27 +51,21 @@ class TemplateImage
/**
* Путь к изображению
*/
function resourcePath($path)
function resourcePath(string $path)
{
assert(is_string($path));
$this->resource = $path;
}
/**
* Путь у шрифтам
*/
function fontPath($path)
function fontPath(string $path)
{
assert(is_string($path));
$this->base = $path;
}
function set($name, $value)
function set(string $name, $value)
{
assert(is_string($name));
$this->context['['.$name.']'] = $this->encode($value);
}
@ -90,10 +83,8 @@ class TemplateImage
/**
* Создает изображение из файла
*/
function imagefromfile($file)
function imagefromfile(string $file)
{
assert(is_string($file));
$suffix = pathinfo($file, PATHINFO_EXTENSION);
if (array_key_exists($suffix, self::$listfiles)) {
return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file);
@ -101,17 +92,15 @@ class TemplateImage
return null;
}
function getFontFile($name)
function getFontFile(string $name)
{
assert(is_string($name));
if(array_key_exists(strtolower($name), self::$listfonts)) {
return $this->base . self::$listfonts[$name];
}
return $this->base . 'arial.ttf';
}
function fontSuffix($style)
function fontSuffix(array $style)
{
if($style[0] && $style[1]) return "z";
@ -121,7 +110,11 @@ class TemplateImage
return "";
}
function imageText($text, $value/*: \stdClass*/)
/**
* @param string $text
* @param object $value
*/
function imageText($text, $value)
{
assert(is_string($text));
@ -130,29 +123,30 @@ class TemplateImage
$fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle));
$color = intval(substr($value->color, 1), 16);
if ($value->align[0]) {
if ($value->align[0]) {
$align = Drawing::ALIGN_LEFT;
} elseif ($value->align[2]) {
} elseif ($value->align[2]) {
$align = Drawing::ALIGN_RIGHT;
} else {
$align = Drawing::ALIGN_CENTER;
}
if ($value->valign[0]) {
if ($value->valign[0]) {
$valign = Drawing::ALIGN_TOP;
} elseif ($value->valign[1]) {
} elseif ($value->valign[1]) {
$valign = Drawing::ALIGN_CENTER;
} else {
$valign = Drawing::ALIGN_BOTTOM;
}
Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
$value->width, $value->height,
$align, $valign);
}
/**
* Перекодировка текста
* @deprecated
*/
function encode($text)
{
@ -160,6 +154,10 @@ class TemplateImage
return $text; //iconv("WINDOWS-1251", "UTF-8", $text);
}
/**
* @param int $new_width
* @param int $new_height
*/
function setSize($new_width, $new_height)
{
$width = imagesx($this->image);