| core_gfx

# Class: Bs_TextType Source Location: /core/gfx/text/Bs_TextType.class.php
### Class Overview
    Bs_Object
       |
       --Bs_TextType
TextType class. #### Author(s): andrej arn <at blueshoes dot org> #### Version: 4.5.$Revision: 1.7 $ $Date: 2003/11/21 17:06:29 $ #### Copyright: blueshoes.org | ### Variables $angle $bgDir $bgImage $Bs_ColorCodes $Bs_Url $fontAntiAlias $fontDir $fontFace $fontSize $imgHeight $imgType $imgWidth $lineSpacing $posX $posY $profileName $store $xAlign $yAlign | ### Methods Bs_TextType calculateImageSize create destruct doItYourself generateFileName get getRequestedFileName getRequestedTextCleaned loadProfile save send set setBgColor setFontColor setFromRequest setText
### Inherited Variables | ### Inherited Methods #### Class: Bs_Object Bs_Object::Bs_Object() Bs_Object::getErrors() Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack. Bs_Object::getLastError() Basic error handling: Get last error string from the global Bs_Error-error stack. Bs_Object::getLastErrors() Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors(). Bs_Object::persist() Persists this object by serializing it and saving it to a file with unique name. Bs_Object::setError() Basic error handling: Push an error string on the global Bs_Error-error stack. Bs_Object::toHtml() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::toString() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::unpersist() Fetches an object that was persisted with persist()
### Class Details [line 84] TextType class. creates images with text on it (for titles, navigation etc) that look better than just plain text. no need to have a designer create [all] the new title images just because the boss wants another text, font or color.
     Features:
       - Define the font face, size, and text color
       - Use any font you want and have on your server
       - Antialiasing
       - Transparency
       - Background colors or background images
       - Create multiline text
       - Specify width/height or have it auto-calculated
       - Define the posX posY (x-axis, y-axis)
       - Have text aligned to the right
       - Draw the text with an angle, for example 90 degrees
       - Automatically store (cache) the images on the server
       - Use profiles and/or pass params in the URL
Limits: windows can store files with up to 103 characters, including extension. it is still possible to create text images with longer texts, but it won't be cached. somehow apache returns a 'forbidden' for url's with 230 or more characters. don't know why yet.
     example 1:
       $tt =& new Bs_TextType();
       $tt->fontSize  = 14;
       $tt->fontFace  = 'courbd';
       $tt->setText("Hello World");
       $tt->create();
       $tt->send();
       $tt->destruct();

     example 2:
       $tt =& new Bs_TextType();
       $tt->imgWidth  = 480;
       $tt->imgHeight = 53;
       $tt->posX      = 1;
       $tt->posY      = 36;
       $tt->fontSize  = 48;
       $tt->fontFace  = 'BKANT'; //courbd
       $tt->setFontColor('#182842');
       $tt->setText("Hello World");
       $tt->create();
       $tt->send();
       $tt->destruct();
special cases: multiline text the $imgHeight will be multiplied by the number of lines. dependencies: Bs_Url, Bs_ColorCodes, Bs_Dir #### Tags:
todo: | see above
example: | example
example: | example
pattern: | singleton: (pseudostatic)
access: | public
copyright: | blueshoes.org
version: | 4.5.$Revision: 1.7 $ $Date: 2003/11/21 17:06:29 $
since: | bs4.1
author: | andrej arn <at blueshoes dot org>
[ Top ] ### Class Variables #### $angle = 0 [line 229] rotates the text. = no, 0 degrees 90 = written from bottom up, lay your head to the left to read it. 180 = text on the head, written from right to left 270 = written from top down, lay your head to the right to read it. you can also use any other angle, from 0 to 360. #### Tags:
since: | bs4.4
access: | public
Type: | int
[ Top ] #### $bgDir = [line 151] if you use a background image then you can specify the path to it. #### Tags:
see: | Bs_TextType::$bgImage
access: | public
Type: | string
[ Top ] #### $bgImage = [line 163] if you want to use a background image for your new text image, name it here. if you do so, $imgWidth and $imgHeight will be ignored. your new image will have the size of the bg image. #### Tags:
see: | Bs_TextType::$bgDir
access: | public
Type: | string
[ Top ] #### $Bs_ColorCodes = [line 99] instance of Bs_ColorCodes. #### Tags:
since: | bs4.3
access: | public
Type: | object
[ Top ] #### $Bs_Url = [line 91] instance of Bs_Url #### Tags:
access: | public
Type: | object
[ Top ] #### $fontAntiAlias = [line 116] if antialias should be used or not. note that by setting the fontColor to a negative number you can do this. read the php manual. #### Tags:
todo: | use this?
Type: | mixed
[ Top ] #### $fontDir = '../_fonts/' [line 104] #### Tags:
access: | public
Type: | mixed
[ Top ] #### $fontFace = [line 109] #### Tags:
access: | public
Type: | mixed
[ Top ] #### $fontSize = [line 122] #### Tags:
access: | public
Type: | int
[ Top ] #### $imgHeight = [line 185] the height of the image. has to be specified, in pixels. 300 => 300 pixel 'auto' => calculated based on the given text. '+15' => calculated based on the given text, extended by 15 pixel. #### Tags:
var: | (int, or string 'auto', read above.)
access: | public
Type: | mixed
[ Top ] #### $imgType = [line 237] one of 'gif', 'jpg', 'png'. default is png. use lowercase! #### Tags:
access: | public
Type: | string
[ Top ] #### $imgWidth = [line 174] the width of the image. in pixels. 300 => 300 pixel 'auto' => calculated based on the given text. '+15' => calculated based on the given text, extended by 15 pixel. #### Tags:
var: | (int, or string 'auto', read above.)
access: | public
Type: | mixed
[ Top ] #### $lineSpacing = '1.0' [line 246] used for multiline text. default is '1.0', can be something like '0.8' or '1.5' or so. #### Tags:
since: | bs-4.5
access: | public
Type: | string
[ Top ] #### $posX = [line 193] the position on the x-axis where to start with the text. used to better adjust the text. #### Tags:
access: | public
Type: | int
[ Top ] #### $posY = [line 201] the position on the y-axis where to start with the text. used to better adjust the text. #### Tags:
access: | public
Type: | int
[ Top ] #### $profileName = [line 280] if you use doItYourself() then this profile will be used. #### Tags:
todo: | maybe add a profileDir var?
access: | public
Type: | bool
[ Top ] #### $store = [line 271] if you use doItYourself() then the file will be automatically persisted on the server when this is TRUE (default). #### Tags:
access: | public
Type: | bool
[ Top ] #### $xAlign = 'left' [line 210] the vertical alignment. 'left' (default) or 'right'. #### Tags:
todo: | support 'middle'
since: | bs4.3
access: | public
Type: | string
[ Top ] #### $yAlign = 'top' [line 216] #### Tags:
see: | var $xAlign
todo: | all
Type: | mixed
[ Top ] ### Class Methods ### constructor Bs_TextType [line 286]
`Bs_TextType Bs_TextType( )`
constructor [ Top ] ### method calculateImageSize [line 681]
`array calculateImageSize( )`
calculates the image width and height. takes posX into account, if set. #### Tags:
return: | (3 elements, 0=width, 1=height, 2=lineHeight)
access: | public
[ Top ] ### method create [line 539]
`int create( )`
create the image based on the instance vars. the return value was previously a bool, but now it's an int like this: => everything ok => some image has been crated, but with fallback stuff. (no truetype or so) -1 => failed hint: if you don't get a 1 back, you may not want to cache the image. #### Tags:
return: | (see above)
see: | Bs_TextType::get(), Bs_TextType::save(), Bs_TextType::send()
access: | public
[ Top ] ### method destruct [line 306]
`void destruct( )`
destructor. please call it. #### Tags:
access: | public
[ Top ] ### method doItYourself [line 321]
`void doItYourself( [array $defaults = array()])`
does everything itself. reads and parses the request url, sets properties, loads profile, creates, saves and sends the image. does whatever is needed to do these tasks. #### Tags:
since: | bs-4.5
access: | public
#### Parameters:
array | $defaults | (hash)
[ Top ] ### method generateFileName [line 768]
`string generateFileName( )`
#### Tags:
access: | public
[ Top ] ### method get [line 723]
`? get( )`
returns the image. call create() before calling this one. #### Tags:
see: | Bs_TextType::create(), Bs_TextType::save(), Bs_TextType::send()
access: | public
[ Top ] ### method getRequestedFileName [line 466]
`string getRequestedFileName( )`
returns the name of the file the user wanted, like "something.png". #### Tags:
throws: | bool false (if we cannot tell).
access: | public
[ Top ] ### method getRequestedTextCleaned [line 481]
`void getRequestedTextCleaned( )`
#### Tags:
deprecated: |
[ Top ] ### method loadProfile [line 859]
`bool loadProfile( string $profileName)`
loads the profile specified. #### Tags:
since: | bs-4.5
access: | public
#### Parameters:
string | $profileName |
[ Top ] ### method save [line 803]
`bool save( [string $path = NULL], [bool $pathIncludesFile = TRUE])`
saves the image to the given path. if the path is not given then the file/path requested by the user will be used. that's what you want if you don't want something customized. call create() before calling this one. if the path does not exist the method will attempt to create it (since bs4.3). #### Tags:
see: | Bs_TextType::create(), Bs_TextType::get(), Bs_TextType::send()
access: | public
#### Parameters:
string | $path |
bool | $pathIncludesFile |
[ Top ] ### method send [line 738]
`void send( )`
sends the created image to the browser directly. does not stop code from executing. you may finish some other stuff, but you may not output other things to the browser. don't output anything at all (even before) to the browser when calling this one. just one image is all the browser expects. #### Tags:
see: | Bs_TextType::create(), Bs_TextType::get(), Bs_TextType::save()
access: | public
[ Top ] ### method set [line 917]
`void set( mixed $param, mixed $value)`
setter for all params. #### Tags:
since: | bs-4.5
access: | public
[ Top ] ### method setBgColor [line 900]
`void setBgColor( mixed $color)`
see setFontColor(). #### Tags:
since: | bs4.4
see: | var $_bgColor, Bs_TextType::setFontColor()
access: | public
#### Parameters:
mixed | $color | (see above)
[ Top ] ### method setFontColor [line 881]
`void setFontColor( mixed $color)`
rgb value like array(15, 20, 30), hex string like "#FFFFFF" or "ffffff", or color name string like "antiquewhite". #### Tags:
since: | bs4.4
see: | var $_fontColor
access: | public
#### Parameters:
mixed | $color | (see above)
[ Top ] ### method setFromRequest [line 395]
`void setFromRequest( )`
!!! DEPRECATED !!! sets the text and image type from the request. used with .htaccess and redirect (see the blueshoes site example). call this method after setting the properties like imgHeight. may also overwrite already set properties like posX if they're in the querystring. #### Tags:
access: | public
deprecated: |
[ Top ] ### method setText [line 500]
`void setText( mixed $text)`
sets the text. may be an array for multiline. //@deprecated #### Tags:
see: | var $_text
access: | public
#### Parameters:
mixed | $text | (string or vector)
[ Top ] Documentation generated on Mon, 29 Dec 2003 21:13:09 +0100 by phpDocumentor 1.2.3