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

Class: Image_Text

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

Class Overview


Image_Text - Advanced text maipulations in images


Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 76]
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 198]

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 alignement 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(
                                    'r' => 0, 'g' => 0, 'b' => 0, 'a'=>0
                                   ),'color_mode'=>'line',// font settings
'font_path'=>"./",'font_file'=>null,'font_size'=>2,'line_spacing'=>0.5,// automasurizing settings
'min_font_size'=>1,'max_font_size'=>100,// misc settings
'image_type'=>IMAGETYPE_PNG,'dest_file'=>'')

[line 86]

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

Type:   array


[ Top ]



Method Detail

Image_Text (Constructor)   [line 250]

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 544]

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 ]

display   [line 905]

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 886]

resource &getImg( )

Return the image ressource.

Get the image canvas.

  • Return: Used image resource
  • Access: public

[ Top ]

init   [line 456]

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 589]

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 751]

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 957]

bool save( [string $destFile = false])

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 save() method, too.


Parameters:

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

[ Top ]

set   [line 317]

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.

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'.

      'font_path'         | Location of the font to use.
      'font_file'         |

      '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.


Parameters:

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

[ Top ]

setColor   [line 408]

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 372]

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 10:14:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.