PHPackages                             priler/text2image - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. priler/text2image

ActiveLibrary

priler/text2image
=================

The most useful &amp; easy for use PHP library for converting any text to image. Uses GD extension.

344179[2 issues](https://github.com/Priler/Text2Image/issues)PHP

Since Jan 7Pushed 8y ago4 watchersCompare

[ Source](https://github.com/Priler/Text2Image)[ Packagist](https://packagist.org/packages/priler/text2image)[ RSS](/packages/priler-text2image/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Text2Image
==========

[](#text2image)

The most useful &amp; easy2use PHP library for converting any text into image
Version : 1.0 Beta
Requirements: PHP-GD

Text2Image was created basically for translating any text information into an image representation.
And the point is, that there are no other libs for this task, at least there are no such easy4use libs for such tasks.
So all you need is require header file of this lib, create an instance and call "output" or "save" function, that's it! :)

\###About modes There is exactly 2 modes in it, "Simple" and "Smart".
The main difference between them is that "Simple" is a lot faster than "Smart".
But, "Simple" mode not support's text-size and angle params.
Also, to use custom fonts in "Simple" mode you need to convert them into GDF.
With "Smart" mode you can use any font's you want, of course, if they are supported by GD, for example, TTF work nice.
See "List of all public methods" below for understanding how to switch between this modes.

\###List of all public params:

- $width = 720, // Width of image box, text will be wrapped withing this box \[int\]
- $font = 5, // Font name/family, can be integer font index for Simple mode, or path to TrueType font for Smart mode \[int\] or \[string\]
- $line\_height = 'auto', // Height between lines, can be integer or 'auto' \[int\] or \[string\]
- $background\_color = array(38, 50, 56), // Color of background, can be array of RGB values, or a hex string \[array\] or \[string\]
- $text\_color = array(255, 255, 255), // Color of text, can be array of RGB values, or a hex string \[array\] or \[string\]
- $padding = 30, // Padding by all side's \[int\]
- $angle = 0, // smart-only Text angle \[int\]
- $text\_size = 17, // smart-only Font size \[int\]
- $user\_fonts = array(); // User defined font's

\###List of all public methods:

- get\_mode() - Return current mode, true is "Simple", false is "Smart" \[boolean\]
- set\_mode($mode) - Allows you to switch between modes, accepts "simple" or "smart" string in first parameter
- get\_text() - Return source text
- set\_text($new\_text) - Allows you to set new text
- add\_font($label, $path, $\[force\_mode = null\]) - Using this you can easy add any font you want, by adding "label" you can name added font as you want, "path" defines path to you'r font, "force\_mode" can be used to force used mode on font load operation (1 is "Simple", 0 is "Smart")
- get\_font($label) - Use this to get loaded font index by it's label, then you can pass this index into "font" param
- is\_imagetype\_supported($type) - Return's True if passed type is supported by you'r PHP build, and false if it's not
- output($type = 'png', $quality = 100) - Output result image into browser
- save($path, $type = 'png', $quality = 100) - Allows you to save result image into image, "quality" parameter is supported only with 'jpg' or 'png' image types

Also, see "examples" folder for more.

\###Basic usage example

```
