TIC – Text Image Converter

This is a php5 library (two classes) I wrote to convert TrueType Font text into an image, using the GD library.
The project is hosted and can be downloaded from github: http://github.com/hayate/tic (it includes an example, documentation and some free fonts)
or using git: git clone git://github.com/hayate/tic.git
Documentation is also available online here: http://www.andreabelvedere.com/docs/tic/

To extend the library to add support for other Font types just extend the TIC abstract class and implement the create and dimension methods.

See example below on how to use it:

 * @file image.php
require_once 'lib/tic.php';
    ->setText('Hello World !')
    ->setBgColor(0x00, 0xff, 0xff)
    ->setFontColor(0x00, 0x00, 0x00)

Than in your html:

<img src="image.php" alt="TIC" />

That will output the following image:


The library is under the LGPL license, which means you can freely use it for commercial and non commercial applications, please post a comment for feedbacks, bugs, or links of projects where you have use it.

6 thoughts on “TIC – Text Image Converter

  1. How is it possible to generate images from TTF fonts for chinese characters? I do not know how to get those UNICODE characters as arguments to setText. I did also try to use the PHP image library directly but ran into similar problems, the PHP-chr() function allows only ASCII.

    I do have TTF font files (from university of Heidelberg) and want to generate chinese texts from a database using PHP.

  2. Hi Martin,
    I am not sure I have fully understood what you are asking, however I have run this test with a Japanese font and it works perfectly:

    require_once dirname($_SERVER['DOCUMENT_ROOT']) . '/tic/lib/tic.php';
    $fontfile = dirname($_SERVER['DOCUMENT_ROOT']) . '/tic/fonts/ttf-japanese-mincho.ttf';
    $tic = TIC::factory($fontfile);
    ->setBackground(0xaa, 0xaa, 0xaa)
    ->setColor(array(0x00, 0x00, 0x00))
    ->create(true); // create and output

    And the output is here below:

    In your case you will pass text to setText as follow: setText($unicode); where $unicode will hold your unicode string from the database.
    Hope this helps.

  3. Hello!Do you know or use CodeIgniter?Do you think you can help me to transform your class into a CodeIgniter class, with the possibility to use a function with parameters like in the example:

    <img src="function('Text to appear', 'font', 'font-size', 'color')" alt="" />Thank you in advance for your answer!

    Thank you in advance for your answer!Flaviu

  4. Hi, it is not working with me,<?phprequire_once ‘lib/tic.php’;TIC::factory(‘fonts/mlkarthika.ttf’)->setText(‘നമഃ  ശിവായ ‘)->setPadding(10)->setBgColor(‘ff0000’)->setFontColor(0xff, 0xff, 0x00)->setFontSize(24)->create(true);?>and the out put is an image containing “???????”. please help me

Leave a Reply

Your email address will not be published. Required fields are marked *