style: Форматирование

This commit is contained in:
origami11@yandex.ru 2024-08-29 11:11:20 +03:00
parent 8941f5f102
commit d692538163
9 changed files with 92 additions and 92 deletions

View file

@ -9,8 +9,8 @@ class Drawing
const ALIGN_BOTTOM = "bottom";
const ALIGN_CENTER = "center";
const ALIGN_RIGHT = "right";
static function drawrectnagle(&$image, $left, $top, $width, $height, $rgb)
static function drawrectnagle(&$image, $left, $top, $width, $height, $rgb)
{
$color = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
$right = $left + $width;
@ -22,68 +22,69 @@ class Drawing
}
/**
* http://ru2.php.net/imagettftext
* http://ru2.php.net/imagettftext
*/
static function imagettftextbox(&$image, $size, $angle, $left, $top, $color, $font, $text,
static function imagettftextbox(&$image, $size, $angle, $left, $top, $color, $font, $text,
$max_width, $max_height, $align, $valign)
{
// echo $left,"\n", $top, "\n";
// echo $max_width,"\n", $max_height, "\n";
// self::drawrectnagle($image, $left, $top, $max_width, $max_height, array(0xFF,0,0));
$text_lines = explode("\n", $text); // Supports manual line breaks!
$lines = [];
$line_widths = [];
$largest_line_height = 0;
$largest_line_height = 0;
foreach ($text_lines as $block) {
$current_line = ''; // Reset current line
$words = explode(' ', $block); // Split the text into an array of single words
$current_line = ''; // Reset current line
$words = explode(' ', $block); // Split the text into an array of single words
$first_word = true;
$last_width = 0;
$last_width = 0;
$count = count($words);
$item = '';
for ($i = 0; $i < $count; $i++) {
$item = $words[$i];
$dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item);
$line_width = $dimensions[2] - $dimensions[0];
$line_height = $dimensions[1] - $dimensions[7];
$largest_line_height = max($line_height, $largest_line_height);
if ($line_width > $max_width && !$first_word) {
$lines[] = $current_line;
$line_widths[] = $last_width ?: $line_width;
$current_line = $item;
} else {
$current_line .= ($first_word ? '' : ' ') . $item;
}
if ($i == count($words) - 1) {
$lines[] = $current_line;
$lines[] = $current_line;
$line_widths[] = $line_width;
}
$last_width = $line_width;
$last_width = $line_width;
$first_word = false;
}
if ($current_line) {
$current_line = $item;
}
}
// vertical align
$top_offset = 0;
if ($valign == self::ALIGN_CENTER) {
$top_offset = ($max_height - $largest_line_height * count($lines)) / 2;
} elseif ($valign == self::ALIGN_BOTTOM) {
$top_offset = $max_height - $largest_line_height * count($lines);
}
}
$top += $largest_line_height + $top_offset;
$i = 0;
foreach ($lines as $line) {
// horizontal align
@ -93,17 +94,17 @@ class Drawing
} elseif ($align == self::ALIGN_RIGHT) {
$left_offset = ($max_width - $line_widths[$i]);
}
imagettftext($image, $size, $angle, $left + $left_offset, $top + ($largest_line_height * $i), $color, $font, $line);
$i++;
}
return $largest_line_height * count($lines);
}
function imagettftextSp($image, $size, $angle, $x, $y, $color, $font, $text, $spacing = 0)
{
{
if ($spacing == 0)
{
imagettftext($image, $size, $angle, $x, $y, $color, $font, $text);