Text
[ class tree: Text ] [ index: Text ] [ all elements ]

Class: Image_Text

Source Location: /Image_Text-0.6.0/Image/Text.php

Class Overview


Image_Text - Advanced text maipulations in images


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 1997-2005 The PHP Group

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 144]
Image_Text - Advanced text maipulations in images

Image_Text provides advanced text manipulation facilities for GD2 image generation with PHP. Simply add text clippings to your images, let the class automatically determine lines, rotate text boxes around their center or top left corner. These are only a couple of features Image_Text provides.



[ Top ]


Class Variables

$colors = array()

[line 320]

Color indeces returned by imagecolorallocatealpha.
  • Access: public

Type:   array


[ Top ]

$options = array(
            // orientation
            'x'                 => 0,
            'y'                 => 0,

            // surface
            'canvas'            => null,
            'antialias'         => true,

            // text clipping
            'width'             => 0,
            'height'            => 0,

            // text alignment inside the clipping
            'halign'             => IMAGE_TEXT_ALIGN_LEFT,
            'valign'             => IMAGE_TEXT_ALIGN_TOP,

            // angle to rotate the text clipping
            'angle'             => 0,

            // color settings
            'color'             => array( '#000000' ),'color_mode'=>'line','background_color'=>'#000000','enable_alpha'=>false,// font settings
'font_path'=>"./",'font_file'=>null,'font_size'=>2,'line_spacing'=>0.5,// automasurizing settings
'min_font_size'=>1,'max_font_size'=>100,//max. lines to render
'max_lines'=>100,// misc settings
'image_type'=>IMAGETYPE_PNG,'dest_file'=>'')

[line 204]

Options array. these options can be set through the constructor or the set() method.

Possible options to set are:

      'x'                 | This sets the top left coordinates (using x/y) or the center point
      'y'                 | coordinates (using cx/cy) for your text box. The values from
      'cx'                | cx/cy will overwrite x/y.
      'cy'                |

      'canvas'            | You can set different values as a canvas:
                          |   - A gd image resource.
                          |   - An array with 'width' and 'height'.
                          |   - Nothing (the canvas will be measured after the real text size).

      'antialias'         | This is usually true. Set it to false to switch antialiasing off.

      'width'             | The width and height for your text box.
      'height'            |

      'halign'            | Alignment of your text inside the textbox. Use alignmnet constants to define
      'valign'            | vertical and horizontal alignment.

      'angle'             | The angle to rotate your text box.

      'color'             | An array of color values. Colors will be rotated in the mode you choose (linewise
                          | or paragraphwise). Can be in the following formats:
                          |   - String representing HTML style hex couples (+ unusual alpha couple in the first place, optional).
                          |   - Array of int values using 'r', 'g', 'b' and optionally 'a' as keys.

      'color_mode'        | The color rotation mode for your color sets. Does only apply if you
                          | defined multiple colors. Use 'line' or 'paragraph'.

      'background_color'  | defines the background color. NULL sets it transparent
      'enable_alpha'      | if alpha channel should be enabled. Automatically
                          | enabled when background_color is set to NULL

      'font_path'         | Location of the font to use. The path only gives the directory path (ending with a /).
      'font_file'         | The fontfile is given in the 'font_file' option.

      'font_size'         | The font size to render text in (will be overwriten, if you use automeasurize).

      'line_spacing'      | Measure for the line spacing to use. Default is 0.5.

      'min_font_size'     | Automeasurize settings. Try to keep this area as small as possible to get better
      'max_font_size'     | performance.

      'image_type'        | The type of image (use image type constants). Is default set to PNG.

      'dest_file'         | The destination to (optionally) save your file.


Type:   array


[ Top ]



Method Detail

Image_Text (Constructor)   [line 372]

Image_Text Image_Text( string $text, [array $options = null])

Constructor

Set the text and options. This initializes a new Image_Text object. You must set your text here. Optinally you can set all options here using the $options parameter. If you finished switching all options you have to call the init() method first befor doing anything further! See Image_Text::set() for further information.


Parameters:

string   $text   —  Text to print.
array   $options   —  Options.

[ Top ]

autoMeasurize   [line 704]

int autoMeasurize( [int $start = false], [int $end = false])

Auto measurize text

Automatically determines the greatest possible font size to fit the text into the text box. This method may be very resource intensive on your webserver. A good tweaking point are the $start and $end parameters, which specify the range of font sizes to search through. Anyway, the results should be cached if possible. You can optionally set $start and $end here as a parameter or the settings of the options array are used.


Parameters:

int   $start   —  Fontsize to start testing with.
int   $end   —  Fontsize to end testing with.

[ Top ]

construct   [line 392]

void &construct( string $text, array $options)

Construct and initialize an Image_Text in one step.

This method is called statically and creates plus initializes an Image_Text object. Beware: You will have to recall init() if you set an option afterwards manually.


Parameters:

string   $text   —  Text to print.
array   $options   —  Options.

[ Top ]

display   [line 1068]

bool display( [bool $save = false], [bool $free = false])

Display the image (send it to the browser).

This will output the image to the users browser. You can use the standard IMAGETYPE_* constants to determine which image type will be generated. Optionally you can save your image to a destination you set in the options.


Parameters:

bool   $save   —  Save or not the image on printout.
bool   $free   —  Free the image on exit.

[ Top ]

getImg   [line 1049]

resource &getImg( )

Return the image ressource.

Get the image canvas.

  • Return: Used image resource
  • Access: public

[ Top ]

init   [line 561]

bool init( )

Initialiaze the Image_Text object.

This method has to be called after setting the options for your Image_Text object. It initializes the canvas, normalizes some data and checks important options. Be shure to check the initialization after you switched some options. The set() method may force you to reinitialize the object.

  • Return: True on success, otherwise PEAR::Error.
  • See: Image_Text::set()
  • Access: public

[ Top ]

measurize   [line 749]

array measurize( [bool $force = false])

Measurize text into the text box

This method makes your text fit into the defined textbox by measurizing the lines for your given font-size. You can do this manually before rendering (or use even Image_Text::autoMeasurize()) or the renderer will do measurizing automatically.


Parameters:

bool   $force   —  Optionally, default is false, set true to force measurizing.

[ Top ]

render   [line 914]

bool render( [bool $force = false])

Render the text in the canvas using the given options.

This renders the measurized text or automatically measures it first. The $force parameter can be used to switch of measurizing problems (this may cause your text being rendered outside a given text box or destroy your image completely).

  • Return: True on success, otherwise PEAR::Error.
  • Access: public

Parameters:

bool   $force   —  Optional, initially false, set true to silence measurize errors.

[ Top ]

save   [line 1120]

bool save( [ $dest_file = false], string $destFile)

Save image canvas.

Saves the image to a given destination. You can leave out the destination file path, if you have the option for that set correctly. Saving is possible with the display() method, too.


Parameters:

string   $destFile   —  The destination to save to (optional, uses options value else).
   $dest_file   — 

[ Top ]

set   [line 416]

bool set( mixed $option, [mixed $value = null])

Set options

Set a single or multiple options. It may happen that you have to reinitialize the Image_Text object after changing options. For possible options, please take a look at the class options array!


Parameters:

mixed   $option   —  A single option name or the options array.
mixed   $value   —  Option value if $option is string.

[ Top ]

setColor   [line 507]

bool setColor( mixed $color, [mixed $id = 0])

Set a color

This method is used to set a color at a specific color ID inside the color cycle.

The following colors syntaxes are understood by this method:

  • "#ffff00" hexadecimal format (HTML style), with and without #.
  • "#08ffff00" hexadecimal format (HTML style) with alpha channel (08), with and without #.
  • array with 'r','g','b' and (optionally) 'a' keys, using int values.


Parameters:

mixed   $color   —  Color value.
mixed   $id   —  ID (in the color array) to set color to.

[ Top ]

setColors   [line 471]

bool setColors( mixed $colors)

Set the color-set

Using this method you can set multiple colors for your text. Use a simple numeric array to determine their order and give it to this function. Multiple colors will be cycled by the options specified 'color_mode' option. The given array will overwrite the existing color settings!

The following colors syntaxes are understood by this method:

  • "#ffff00" hexadecimal format (HTML style), with and without #.
  • "#08ffff00" hexadecimal format (HTML style) with alpha channel (08), with and without #.
  • array with 'r','g','b' and (optionally) 'a' keys, using int values.
  • a GD color special color (tiled,...).
A single color or an array of colors are allowed here.


Parameters:

mixed   $colors   —  Single color or array of colors.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:40:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.