PHP Classes

Image Font: Render images with text using graphics as fonts

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 642 All time: 4,979 This week: 455Up
Version License PHP version Categories
image-font 1.0BSD License5.0PHP 5, Graphics, Text processing
Description 

Author

This class can render images with text using graphics as fonts.

It takes a text string and creates an image on which the characters of the string are displayed using separate image files to render each character.

The text may be aligned to the left, right, center or be justified.

The image width may be limited so the text is wrapped if it exceeds that width limit.

The character graphics may be mapped to image files with the same base name in a given directory. Alternatively an array may be passed to define the paths of the character image files.

The generated image may be saved to a file or displayed as the current script output in any of the formats supported by the PHP GD image extension.

Innovation Award
PHP Programming Innovation award winner
January 2012
Winner


Prize: One downloadable e-book of choice by O'Reilly
Some applications need to use buttons or other types of images on which a given text message is rendered.

If there is no font with characters with a certain aspect that you want to use, you can always create images in PHP by pasting other images that represent the text characters of the message you want to display.

In some cases you may need to render text formatted with special justification.

This class provides solution to render text on images using separate image files as font characters.

You can format the text using several types of justification, in such way that if the text does not fit a given limit width, it can nicely wrap the text around multiple lines.

Manuel Lemos
Picture of Arturs Sosins
  Performance   Level  
Name: Arturs Sosins <contact>
Classes: 22 packages by
Country: Latvia Latvia
Age: 36
All time rank: 521 in Latvia Latvia
Week rank: 50 Up1 in Latvia Latvia Equal
Innovation award
Innovation award
Nominee: 13x

Winner: 2x

Example

<?php
/*************************************************************
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com
 * Feel free to distribute and modify code, but keep reference to its creator
 *
 * Image Font class can generate text taking images of symbols as font.
 * You can provide path to directory with images, using symbols as file names,
 * or you can provide and array with symbols as keys and paths to images as values.
 * It is also possible to set a maximal width restriction and alignment of text.
 *
 * For more information, examples and online documentation visit:
 * http://webcodingeasy.com/PHP-classes/Generate-text-using-images-as-letters
**************************************************************/

if(isset($_GET["type"]))
{
    include(
"image_font.php");
   
$imf = new image_font("./digits/");
    switch(
$_GET["type"])
    {
        case
"right":
           
$imf->apply_font("324324 5435 3123123 436554645
            234324 43545345 3435345
            345345345 345345345
            345345345345345 34534534534534
            345345345345 34435345
            443534534534435345345"
, "right");
        break;
        case
"center":
           
$imf->apply_font("324324 5435 3123123 436554645
            234324 43545345 3435345
            345345345 345345345
            345345345345345 34534534534534
            345345345345 34435345
            443534534534435345345"
, "center");
        break;
        case
"justify":
           
$imf->apply_font("324324 5435 3123123 436554645
            234324 43545345 3435345
            345345345 345345345
            345345345345345 34534534534534
            345345345345 34435345
            443534534534435345345"
, "justify");
        break;
        case
"max_width":
           
$imf->apply_font("324324 5435 3123123 436554645
            234324 43545345 3435345
            345345345 345345345
            345345345345345 34534534534534
            345345345345 34435345
            443534534534435345345"
, "left", 500);
        break;
        default:
           
$imf->apply_font("324324 5435 3123123 436554645
            234324 43545345 3435345
            345345345 345345345
            345345345345345 34534534534534
            345345345345 34435345
            443534534534435345345"
);
        break;
    }
   
$imf->output();
}

?>


  Files folder image Files (15)  
File Role Description
Files folder imagedigits (10 files)
Plain text file image_font.php Class Main class source
Accessible without login Plain text file example_from_array.php Example Example loading images from array
Accessible without login Plain text file example_from_directory.php Example Example loading images from directory
Accessible without login Plain text file example_images.html Data Example with multiline text and alignments
Accessible without login Plain text file example_image_generator.php Example Generating images for example file

  Files folder image Files (15)  /  digits  
File Role Description
  Accessible without login Image file 0.png Data Image for 0 digit
  Accessible without login Image file 1.png Data Image for 1 digit
  Accessible without login Image file 2.png Data Image for 2 digits
  Accessible without login Image file 3.png Data Image for 3 digit
  Accessible without login Image file 4.png Data Image for 4 digit
  Accessible without login Image file 5.png Data Image for 5 digit
  Accessible without login Image file 6.png Data Image for 6 digit
  Accessible without login Image file 7.png Data Image for 7 digit
  Accessible without login Image file 8.png Data Image for 8 digit
  Accessible without login Image file 9.png Data Image for 9 digit

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:642
This week:0
All time:4,979
This week:455Up