You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class RichTextLine extends VirtualTextLine
{
/** @return Color */publicfunctiongetFontColor();
/** @param Color $color Font color */publicfunctionsetFontColor(Color$color);
/** @return Color */publicfunctiongetBackgroundColor();
/** @param Color $color Font color */publicfunctionsetBackgroundColor(Color$color);
/** @return Color */publicfunctiongetTextShadowColor();
/** @return Point */publicfunctiongetTextShadowOffset();
/** @return bool */publicfunctionhasTextShadow();
/** * @param Color $color * @param int $x * @param int $y */publicfunctionsetTextShadow(Color$color, $x, $y);
/** @return int */publicfunctiongetStrokeSize();
/** @return Color */publicfunctiongetStrokeColor();
/** @return bool */publicfunctionhasStroke();
/** @param Color $color Stroke color */publicfunctionsetStrokeColor(Color$color);
/** @param int $v Stroke size in *pixels* */publicfunctionsetStrokeSize($v);
/** * @param Color $color * @param $size */publicfunctionsetStroke(Color$color, $size);
/** @return string */publicfunctiongetHorizontalAlignment();
/** @param string $horizontalAlignment */publicfunctionsetHorizontalAlignment($horizontalAlignment);
/** @return float */publicfunctiongetBaseline();
/** @return float */publicfunctiongetLineHeight();
/** @param float $v */publicfunctionsetLineHeight($v);
/** @param float $v Position of baseline, in percents, proportionally to line height measuring from the bottom. */publicfunctionsetBaseline($v);
}
class TextBox
{
/** @param string $verticalAlignment Vertical alignment. Allowed values are: top, center, bottom. */publicfunctionsetVerticalContentAlignment($verticalAlignment = VerticalAlignment::Top);
/** * TextBlock constructor. * @param resource $img Image resource identifier. * @param Rectangle $bounds (x, y, width, height) (Distance in pixels from left edge of image, from top edge, width of textbox in pixels, height). */publicfunction__construct($img, Rectangle$bounds);
/** Enables debug mode. Whole textbox and individual lines will be filled with random colors. */publicfunctionenableDebug();
/** * Draws the text on the picture. * @param RichTextLine|RichTextLine[] $text Text to draw. */publicfunctiondraw($text);
}
// Demo multilined text.$text = newVirtualTextLine();
$text->setText(" Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eleifend congue auctor. Nullam eget blandit magna. Fusce posuere lacus at orci blandit auctor. Aliquam erat volutpat. Cras pharetra aliquet leo. Cras tristique tellus sit amet vestibulum ullamcorper. Aenean quam erat, ullamcorper quis blandit id, sollicitudin lobortis orci. In non varius metus. Aenean varius porttitor augue, sit amet suscipit est posuere a. In mi leo, fermentum nec diam ut, lacinia laoreet enim. Fusce augue justo, tristique at elit ultricies, tincidunt bibendum erat.\n\n Aenean feugiat dignissim dui non scelerisque. Cras vitae rhoncus sapien. Suspendisse sed ante elit. Duis id dolor metus. Vivamus congue metus nunc, ut consequat arcu dapibus vel. Ut sed ipsum sollicitudin, rutrum quam ac, fringilla risus. Phasellus non tincidunt leo, sodales venenatis nisl. Duis lorem odio, porta quis laoreet ut, tristique a justo. Morbi dictum dictum est ut facilisis. Duis suscipit sem ligula, at commodo risus pulvinar vehicula. Sed quis quam ac quam scelerisque dapibus id non justo. Sed mollis enim id neque tempus, a congue nulla blandit. Aliquam congue convallis lacinia. Aliquam commodo eleifend nisl a consectetur.\n\n Maecenas sem nisl, adipiscing nec ante sed, sodales facilisis lectus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut bibendum malesuada ipsum eget vestibulum. Pellentesque interdum tempor libero eu sagittis. Suspendisse luctus nisi ante, eget tempus erat tristique sed. Duis nec pretium velit. Praesent ornare, tortor non sagittis sollicitudin, dolor quam scelerisque risus, eu consequat magna tellus id diam. Fusce auctor ultricies arcu, vel ullamcorper dui condimentum nec. Maecenas tempus, odio non ullamcorper dignissim, tellus eros elementum turpis, quis luctus ante libero et nisi.\n\n Phasellus sed mauris vel lorem tristique tempor. Pellentesque ornare purus quis ullamcorper fermentum. Curabitur tortor mauris, semper ut erat vitae, venenatis congue eros. Ut imperdiet arcu risus, id dapibus lacus bibendum posuere. Etiam ac volutpat lectus. Vivamus in magna accumsan, dictum erat in, vehicula sem. Donec elementum lacinia fringilla. Vivamus luctus felis quis sollicitudin eleifend. Sed elementum, mi et interdum facilisis, nunc eros suscipit leo, eget convallis arcu nunc eget lectus. Quisque bibendum urna sit amet varius aliquam. In mollis ante sit amet luctus tincidunt.");
$text->setFontFile(__DIR__ . '/fonts/Minecraftia-Regular.ttf');
$text->setFontSizePx(8);
$textBounds = newRectangle(20, 40, 460, 460);
$textWrapper = newTextWrapper();
$lines = $textWrapper->wrapTextWithOverflow($text, $textBounds);
foreach ($linesas$i => $line) {
$line->setTextShadow(newColor(15, 15, 15), 1, 1);
$line->setLineHeight($lineHeight);
$line->setBaseline(-0.3);
$line->setFontColor(newColor($i * 8, 75, 140));
}
$textBox = newTextBox($im, $textBounds);
$textBox->setVerticalContentAlignment(VerticalAlignment::Top);
$textBox->draw($lines);
Such API allows for individual control over lines formatting, like in example below:
The text was updated successfully, but these errors were encountered:
There are several open issues asking for text measurement. I want to propose new API for upcoming gd-text release and I invite you to discuss.
Example of new API usage:
Such API allows for individual control over lines formatting, like in example below:
The text was updated successfully, but these errors were encountered: