Download the PHP package teknoo/gd-text without Composer

On this page you can find all versions of the php package teknoo/gd-text. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package gd-text

Teknoo Software - GD-text library

Latest Stable Version Latest Unstable Version Total Downloads License PHPStan

Fork from GdText library to add texts, with some effects and alignments in images thanks to the GdExtension.

Basic usage example

Example output:

Multilined text

Text stroke

Text background

Fit the text to the box

drawFitFontSize() looks for the biggest font size (by steps of $precision) for which the text fits in the box, then draws it. Without $maxFontSize, the font size grows until the text fills the box. Without $minFontSize, the font size can go down to 1. If the text never fits, it is drawn with the minimum font size and overflows. The font size configured with setFontSize() is the starting point and is restored after drawing.

API overview

All setters of GDText\Box return the box itself and can be chained.

Method Description
setFontFace(string $path) Path to the TTF/OTF font file. Required before drawing.
setFontSize(int $size) Font size in pixels (>= 1), default 12.
setFontColor(Color $color) Text color, default black.
setBox(int $x, int $y, int $width, int $height) Area where the text is drawn, default 0, 0, 100, 100.
setTextAlign(HorizontalAlignment $x, VerticalAlignment $y) Alignment of the text in the box, default Left, Top.
setTextWrapping(TextWrapping $wrapping) WrapWithOverflow (default) wraps words on the box width, a word longer than the box overflows. NoWrap draws the text as is.
setLineHeight(float $ratio) Line height as a ratio of the font size (> 0), default 1.25.
setBaseline(float $ratio) Position of the baseline in the line, as a ratio of the line height, default 0.2.
setAngle(int $degrees) Rotation of each line, counter clockwise. The alignment is computed on the unrotated text.
setStrokeColor(Color $color), setStrokeSize(int $pixels) Outline of the text, default none (0).
setTextShadow(Color $color, int $xShift, int $yShift) Shadow of the text, default none.
setBackgroundColor(Color $color) Background behind each non empty line, default none.
enableDebug() Fills the box and each line with random colors to visualize them.
draw(string $text): Rectangle Draws the text and returns the area covered by it.
drawFitFontSize(...) Draws the text with the biggest font size fitting the box, see above.
calculate(string $text): Rectangle Returns the area that draw() would cover, without drawing anything.

GDText\Color represents a 8-bit RGB color with an optional alpha channel (0 opaque to 127 transparent): new Color(255, 75, 140), new Color(0, 0, 0, 50), Color::parseString('#ff4b8c'), Color::parseString('#abc'), Color::fromHsl(0.5, 0.8, 0.3) (each component between 0 and 1). Invalid values raise an InvalidArgumentException. On palette images whose palette is full, the closest color is used.

Security considerations

Support this project

This project is free and will remain free. It is fully supported by commercial activities of SASU Teknoo Software and EIRL Richard DELOGE. If you like it and help me maintain it and evolve it, don't hesitate to support me on Patreon or Github.

Thanks :) Richard.

Credits

EIRL Richard Déloge - https://deloge.io - Lead developer. SASU Teknoo Software - https://teknoo.software

About Teknoo Software

Teknoo Software is a PHP software editor, founded by Richard Déloge, as part of EIRL Richard Déloge. Teknoo Software's goals : Provide to our partners and to the community a set of high quality services or software, sharing knowledge and skills.

License

GdText is licensed under the 3-Clause BSD License - see the LICENSE file for details.

Installation & Requirements

To install this library with composer, run this command :

composer require teknoo/gd-text

This library requires :

* PHP 8.5+
* GD extension with Native TTF support

Demos

Line height demo:

Text alignment demo:

Text stroke demo:

Text background demo:

Debug mode enabled demo:

Contribute :)

You are welcome to contribute to this project. Fork it on Github


All versions of gd-text with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
ext-gd Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package teknoo/gd-text contains the following files

Loading the files please wait ...