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

Class: image_factory

Source Location: /image_factory.php

Class image_factory

Class Overview
Property Summary
static mixed   $referers  
string   $background   Sets the background to be used for the image. This can either be a relative path (from the script) to an image on the server or a hexidecimal color $fontcolor re hex. White will be used if image does not exist or hex value is not valid.
array   $bgdetails   An array of the data returned by getimagesize
string   $cache_directory   The directory (relative from the script (if set through the method)) of where cached images will be stored.
string   $content_after   Text content to place after the dynamic content from the feed. If NULL or false, it will not be used
mixed   $content_after_font   Font to be used for $content_after. If not set, $font will be used
string   $content_after_fontcolor   Color of the $content_after. If this is not set, $fontcolor will be used
int   $content_after_x   The x coordinate where the $content_after will be placed. Default will be 0 (snug to left)
int   $content_after_y   The y coordinate where the $content_after will be placed. Default will be directly underneath $content;
string   $content_before   Text content to place before the dynamic content from the feed. If NULL or false, it will not be used
mixed   $content_before_font   Font to be used for $content_before. If not set, $font will be used
string   $content_before_fontcolor   Color of the $content_before. If this is not set, $fontcolor will be used
int   $content_before_x   The x coordinate where the $content_before will be placed. Default will be 0 (snug to left)
int   $content_before_y   The y coordinate where the $content_before will be placed. Default will be 0 (snug to top);
int   $content_x   The x coordinate where the main content will be placed in the output image. Default will be 0 (snug to left) No check will be mad eto ensure text fits within image.
int   $content_y   The y coordinate where the main content will be placed in the output image. Default will be 0 ( snug to top)
mixed   $dynamic_content  
array   $errors   An array of errors that have accumulated throughout the script.
array   $excluded   An array of the properties that SHOULD NOT be configurable via the $_GET string. This will stop someone dodgy messing stuff up. You may also want to exclude some properties like the feed, the width, height.
array   $extra_tags   The additional XML tags to retrieve from the RSS feed entry. TITLE is mandatory. These will use $font and $fontcolor
mixed   $font   Relative path (from script) the font file to use in image generation or an integer
string   $fontcolor   A six character hexidecimal color string RRGGBB eg, FF00CC
int   $height   The height of the image to output
mixed   $image_functions  
int   $image_quality   Sets the output jpeg quality (1-100)
mixed   $img  
mixed   $img_resource  
array   $mime_types   An array of mime types that a background image can be.
array   $parsed_xml   XML in $xml will be parsed using xml_parse_into_struct, this is an associative array of pointers and data
resource   $parser   The xml parser
array   $request   The HTTPRequest
int   $resample_height  
int   $resample_width   Due to gdf fonts only having one size, you may get your image looking just right only to find
string   $site_feed   The url of the RSS feed that will be the source of the dynamic text in the created image.
int   $width   The width of the image to output
string   $xml   Contains the full, unparsed xml of the RSS feed

[ Top ]
Method Summary
static image_factory   generate_from_request()   Takes $_SERVER['REQUEST_URI'] and parses it into an associative array for use with __construct()
image_factory   __construct()   The contructor function takes an array of data to build the image from.
void   __destruct()   Clean up a bit
bool   check_feed_validity()   Checks $site_feed to ensure it is a valid rss feed
string   check_font()   Check to see if the given font has a file on the server or that it is a number from 1-5.
string   check_hex()   Checks to ensure the given value is a valid RGB hexidecimal color
string   clean_path()   Takes the strings sent through as paths and cleans them remove preceding forward slashes.
void   clear_cache()   Clears out the cache when the dynamic content changes. (when a new blog post occurs), only deletes .jpg images
void   dump_errors()   For debugging purposes, this dumps the stored $errors within some html pre tags
string   generate_filename()   Generates a unique filename based on the current object setup.
string   generate_image()   generates the image that will be returned based on member properties.
resource   generate_image_color()   Allocates a color to an image for use in the output.
void   get_from_cache()   Returns the data from a file in the cache
string   get_latest_entry()   Gets the title of the latest blog entry. Currently this is hardcoded in based on a WordPress RSS feed.
bool   is_hex()   Checks if a string is hex
void   parse_feed()   Parses the xml returned by $site_feed into $data and $pointers
void   set_background()   Checks a given background to see whether it is a file on the server or
void   set_cache_directory()   ..
void   set_content_after()   ..
void   set_content_after_font()   ..
void   set_content_after_fontcolor()   ..
void   set_content_after_x()   ..
void   set_content_after_y()   ..
void   set_content_before()   ..
void   set_content_before_font()   ..
void   set_content_before_fontcolor()   ..
void   set_content_before_x()   ..
void   set_content_before_y()   ..
void   set_content_x()   ..
void   set_content_y()   ..
void   set_dynamic_content()  
void   set_font()   ..
void   set_fontcolor()   ..
void   set_height()   ..
void   set_image_quality()   Sets the value of $image_quality... uses default value if not an int 1-100
void   set_resample_height()   ..
void   set_resample_width()   ..
void   set_site_feed()   ..
void   set_width()   ..
void   write_to_cache()   Takes the image resource in $img and writes it to cache/filename.jpg.

[ Top ]
Properties
static mixed   $referers = array('http://www.lukedingle.com', 'http://lukedingle') [line 24]

[ Top ]
string   $background = 'FFFFFF' [line 84]

Sets the background to be used for the image. This can either be a relative path (from the script) to an image on the server or a hexidecimal color $fontcolor re hex. White will be used if image does not exist or hex value is not valid.

API Tags:
Access:  private


[ Top ]
array   $bgdetails [line 218]

An array of the data returned by getimagesize

API Tags:
Access:  private


[ Top ]
string   $cache_directory = 'cache' [line 235]

The directory (relative from the script (if set through the method)) of where cached images will be stored.

API Tags:
Access:  private


[ Top ]
string   $content_after [line 144]

Text content to place after the dynamic content from the feed. If NULL or false, it will not be used

API Tags:
Access:  private


[ Top ]
mixed   $content_after_font [line 151]

Font to be used for $content_after. If not set, $font will be used

$fontcolor for expected data

API Tags:
Access:  private


[ Top ]
string   $content_after_fontcolor [line 158]

Color of the $content_after. If this is not set, $fontcolor will be used

API Tags:
Access:  private


[ Top ]
int   $content_after_x [line 165]

The x coordinate where the $content_after will be placed. Default will be 0 (snug to left)

API Tags:
Access:  private


[ Top ]
int   $content_after_y [line 172]

The y coordinate where the $content_after will be placed. Default will be directly underneath $content;

API Tags:
Access:  private


[ Top ]
string   $content_before [line 108]

Text content to place before the dynamic content from the feed. If NULL or false, it will not be used

API Tags:
Access:  private


[ Top ]
mixed   $content_before_font [line 115]

Font to be used for $content_before. If not set, $font will be used

$fontcolor for expected data

API Tags:
Access:  private


[ Top ]
string   $content_before_fontcolor [line 122]

Color of the $content_before. If this is not set, $fontcolor will be used

API Tags:
Access:  private


[ Top ]
int   $content_before_x [line 129]

The x coordinate where the $content_before will be placed. Default will be 0 (snug to left)

API Tags:
Access:  private


[ Top ]
int   $content_before_y [line 136]

The y coordinate where the $content_before will be placed. Default will be 0 (snug to top);

API Tags:
Access:  private


[ Top ]
int   $content_x = 0 [line 92]

The x coordinate where the main content will be placed in the output image. Default will be 0 (snug to left) No check will be mad eto ensure text fits within image.

API Tags:
Access:  private


[ Top ]
int   $content_y = 0 [line 101]

The y coordinate where the main content will be placed in the output image. Default will be 0 ( snug to top)

Or if $content_before is set the text will be placed directly underneath $content_before No check will be made to ensure text fits within image

API Tags:
Access:  private


[ Top ]
mixed   $dynamic_content [line 256]
API Tags:
Access:  private


[ Top ]
array   $errors [line 240]

An array of errors that have accumulated throughout the script.

API Tags:
Access:  private


[ Top ]
array   $excluded = array ('img', 'request', 'parser', 'xml', 'parsed_xml', 'errors', 'mime_types', 'bgdetails', 'cache_directory') [line 211]

An array of the properties that SHOULD NOT be configurable via the $_GET string. This will stop someone dodgy messing stuff up. You may also want to exclude some properties like the feed, the width, height.

Note that site feed is in here initially. Think carefully before taking it out as it adds the potential for people to feed from your server to promote their own sites.

API Tags:
Access:  private


[ Top ]
array   $extra_tags [line 201]

The additional XML tags to retrieve from the RSS feed entry. TITLE is mandatory. These will use $font and $fontcolor

API Tags:
Access:  private


[ Top ]
mixed   $font [line 68]

Relative path (from script) the font file to use in image generation or an integer

1-5 that defines a GD module default font to use

API Tags:
Access:  private


[ Top ]
string   $fontcolor = '000000' [line 75]

A six character hexidecimal color string RRGGBB eg, FF00CC

This will be validated prior to use, if given value is not hex, black (000000) will be used

API Tags:
Access:  private


[ Top ]
int   $height = 121 [line 61]

The height of the image to output

API Tags:
Access:  private


[ Top ]
mixed   $image_functions = array('image/gif' => 'imagecreatefromgif',
'image/jpeg' => 'imagecreatefromjpeg',
'image/png' => 'imagecreatefrompng'
)
[line 226]
API Tags:
Access:  private


[ Top ]
int   $image_quality = 80 [line 193]

Sets the output jpeg quality (1-100)

API Tags:
Access:  private


[ Top ]
mixed   $img [line 243]
API Tags:
Access:  private


[ Top ]
mixed   $img_resource [line 242]
API Tags:
Access:  private


[ Top ]
array   $mime_types = array('image/gif', 'image/jpeg', 'image/png') [line 224]

An array of mime types that a background image can be.

API Tags:
Access:  private


[ Top ]
array   $parsed_xml = array('pointers' => false, 'data' => false) [line 47]

XML in $xml will be parsed using xml_parse_into_struct, this is an associative array of pointers and data

see http://php.net/xml_parse_into_struct for details of this function

API Tags:
Access:  private


[ Top ]
resource   $parser [line 254]

The xml parser

API Tags:
Access:  private


[ Top ]
array   $request [line 248]

The HTTPRequest

API Tags:
Access:  private


[ Top ]
int   $resample_height [line 187]
API Tags:
See:  image_factory::$resample_width
Access:  private


[ Top ]
int   $resample_width [line 181]

Due to gdf fonts only having one size, you may get your image looking just right only to find

that it's too big or small. Use this variable to resample from the initial width to a different size same for height

API Tags:
Access:  private


[ Top ]
string   $site_feed = 'http://www.lukedingle.com/feed' [line 31]

The url of the RSS feed that will be the source of the dynamic text in the created image.

API Tags:
Access:  private


[ Top ]
int   $width = 500 [line 54]

The width of the image to output

API Tags:
Access:  private


[ Top ]
string   $xml [line 39]

Contains the full, unparsed xml of the RSS feed

API Tags:
Access:  private


[ Top ]
Methods
static method generate_from_request  [line 816]

  static image_factory generate_from_request( $request $request, [$sep $defaults = array()], [$hyp $sep = 'qp789qp789'], [$defaults $hyp = '56ty65']  )

Takes $_SERVER['REQUEST_URI'] and parses it into an associative array for use with __construct()

The URL should be in the format /key-value/key-value -- any slash should be replaced with $sep

  1. function generate_from_request($request$defaults array()$sep'qp789qp789'$hyp '56ty65')
  2.     {
  3.         $request explode('/'$request);
  4.         
  5.         $vars array();
  6.         
  7.         foreach ($request as $var)
  8.         {
  9.             $bits explode('-'$var2);
  10.             $var str_replace($hyp'-'$var);
  11.             if (!empty($bits[1]))
  12.             $vars[$bits[0]] str_replace($sep'/'urldecode($bits[1]));
  13.         }    
  14.         if (!is_array($defaults))
  15.         {
  16.             $defaults array();
  17.         }
  18.         return new image_factory(array_merge($defaults$vars));
  19.     }

Parameters:
$request   $request:  string a url string
$sep   $defaults:  string the separator string for slashes in values
$hyp   $sep:  string the separator string for hyphens in values
$defaults   $hyp:  If you want to pass through some default values, pass it as an associative array

API Tags:
Return:  returns an instance of image_factory


[ Top ]
Constructor __construct  [line 266]

  image_factory __construct( [$data $data = false]  )

The contructor function takes an array of data to build the image from.

Loops through class properties, checks if they are in $excluded and if they aren't checks to see if $data[propertyname] is set, if it is, it assigns the value to the property via the setter function for that property. This allows the data to be cleaned, only setting the proprty if it is the expected value.

  1. function __construct($data false)
  2.     {
  3.         if (is_array($data)){        
  4.             foreach ($this as $prop => $default_value)
  5.             {
  6.                 
  7.                 if (in_array($prop$this->excluded))
  8.                     continue;
  9.                 
  10.                 if (!empty($data[$prop]))
  11.                 {
  12.                     $method_to_run 'set_' $prop;
  13.                     // Check to ensure there is a setter function 
  14.                     if (method_exists($this$method_to_run))
  15.                     {
  16.                         // try and set the property, else catch it in the errors array
  17.                         try {
  18.                             $this->$method_to_run($data[$prop]);
  19.                         catch (Exception $e{
  20.                             $this->errors[$prop '_value_error'$e->getMessage();
  21.                         }
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.         
  27.         try {
  28.             $this->parse_feed();
  29.         catch (Exception $e{
  30.             $this->errors['XML_parse_error'$e->getMessage();
  31.         }
  32.         
  33.  
  34.     }

Parameters:
$data   $data:  array

API Tags:
Access:  public


[ Top ]
Destructor __destruct  [line 926]

  void __destruct( )

Clean up a bit

  1. function __destruct()
  2.     {
  3.         if (is_resource($this->img))
  4.             imagedestroy($this->img);
  5.         if (is_resource($this->parser))
  6.             xml_parser_free($this->parser);
  7.     }


API Tags:
Access:  public


[ Top ]
check_feed_validity  [line 630]

  bool check_feed_validity( [ $value = false]  )

Checks $site_feed to ensure it is a valid rss feed

  1. function check_feed_validity($value false)
  2.     {
  3.         // get the headers to ensure we have xml
  4.         if (!$request get_headers($value $value $this->site_feed1))
  5.             return false;
  6.             
  7.         //var_dump($request);
  8.         
  9.         if (!preg_match('/^(text\/xml)|(application\/xml);/'$request['Content-Type']))
  10.             return false;
  11.         
  12.         $this->request $request;
  13.         return true;
  14.     }

Parameters:
   $value: 

API Tags:
Return:  true on success, false on failure
Access:  public


[ Top ]
check_font  [line 589]

  string check_font( $val $val  )

Check to see if the given font has a file on the server or that it is a number from 1-5.

  1. function check_font($val)
  2.     {
  3.         if (is_numeric($val))
  4.         {
  5.             if ($val || $val 5)
  6.             {
  7.                 throw new Exception('Font must be a number 0 - 5');
  8.             }
  9.             $font $val;
  10.             
  11.         else {
  12.             if (!preg_match('/\.gdf$/'$val))
  13.                 throw new Exception('Font must be a .gdf file');
  14.             if (!file_exists($val))
  15.                 throw new Exception('Font ' $val ' does not exist on server');
  16.             if (!$font imageloadfont($val))
  17.                 throw new Exception('Could not load font ' $val);
  18.         }
  19.         return $font;
  20.     }

Parameters:
$val   $val:  mixed either a relative string or integer

API Tags:
Return:  returns given svalue if validates as valid font
Access:  private


[ Top ]
check_hex  [line 557]

  string check_hex( $val $val  )

Checks to ensure the given value is a valid RGB hexidecimal color

  1. function check_hex($val)
  2.     {
  3.         if (!preg_match('/^[\dA-Fa-f]{6}$/'$val))
  4.         {
  5.             throw new Exception('Given color is not valid. Correct format is AAEE00 (RRGGBB)');
  6.         }
  7.         return $val;
  8.     }

Parameters:
$val   $val:  string

API Tags:
Return:  returns given value if validates as a hex string
Access:  private


[ Top ]
clean_path  [line 619]

  string clean_path( $val $val  )

Takes the strings sent through as paths and cleans them remove preceding forward slashes.

Also checks to ensure that it's not trying to use another protocol such as http, ftp or file. Returns the string with offending starting characters removed.

  1. function clean_path($val)
  2.     {
  3.         return preg_replace('/^([\/\\\\]+)|(.{,8}tp:\/\/)/'''$val);
  4.     }

Parameters:
$val   $val:  string The string to be checked and cleaned.

API Tags:
Return:  Returns the cleaned string
Access:  private


[ Top ]
clear_cache  [line 887]

  void clear_cache( )

Clears out the cache when the dynamic content changes. (when a new blog post occurs), only deletes .jpg images

  1. function clear_cache()
  2.     {
  3.         $dir dir($this->cache_directory);
  4.         while (false !== ($file $dir->read()))
  5.         {
  6.             if (preg_match('/\.jpg$/'$file))
  7.                 unlink($this->cache_directory '/' $file);
  8.         }
  9.     }


API Tags:
Access:  private


[ Top ]
dump_errors  [line 801]

  void dump_errors( )

For debugging purposes, this dumps the stored $errors within some html pre tags

  1. function dump_errors()
  2.     {
  3.         echo '<pre>'var_dump($this->errors)echo '</pre>';
  4.     }


API Tags:
Access:  public


[ Top ]
generate_filename  [line 902]

  string generate_filename( )

Generates a unique filename based on the current object setup.

This generation includes member properties and xml data to allow consistency

  1. function generate_filename()
  2.     {
  3.         // loop through properties and create a string of the property values that 
  4.         // are allowed to be changed
  5.         $filename '';
  6.         foreach ($this as $name => $prop)
  7.         {
  8.             if (in_array($name$this->excluded))
  9.                 continue;
  10.             $filename .= $this->$name;
  11.         }
  12.         
  13.         // now throw the dynamic content into it
  14.         $filename .= $this->get_latest_entry();
  15.         
  16.         // Now hash it and return md5 should be unique enough for this purpose
  17.         
  18.         return md5($filename'.jpg';
  19.     }


API Tags:
Return:  returns a string filename.
Access:  private


[ Top ]
generate_image  [line 651]

  string generate_image( [$check_cache $check_cache = true], [$add_cache $add_cache = true]  )

generates the image that will be returned based on member properties.

  1. function generate_image($check_cache true$add_cache true)
  2.     {
  3.     
  4.         // If we're checking from the cache, we'll use that image first
  5.         if ($check_cache && ($img $this->get_from_cache()))
  6.             return $img;
  7.             
  8.         // Create the image foundation 
  9.         $img imagecreatetruecolor($this->width$this->height);
  10.         
  11.         // set the background of the image, either from another image or with a color
  12.         if ($this->is_hex($this->background))
  13.         {
  14.             $backgroundcolor $this->generate_image_color($img$this->background);
  15.             imagefill($img00$backgroundcolor);
  16.         else 
  17.         // We are using a background image on the server
  18.             // load the appropriate function
  19.             $bgimage $this->image_functions[strtolower($this->bgdetails['mime'])]($this->background);
  20.             
  21.             // now copy the backgroun dto our new image
  22.             imagecopyresampled($img$bgimage0000$this->width$this->height$this->bgdetails[0]$this->bgdetails[1]);
  23.             // we can get rid of the background image now
  24.             imagedestroy($bgimage);
  25.         }
  26.         
  27.         // Now it's time to load the text into the file image
  28.         
  29.         if ($this->content_before)
  30.         {
  31.             // load up the color
  32.             $content_before_color $this->generate_image_color($img$this->content_before_fontcolor $this->content_before_fontcolor $this->fontcolor);
  33.             
  34.             imagestring($img$this->content_before_font === NULL $this->font $this->content_before_font$this->content_before_x$this->content_before_y$this->content_before$content_before_color);
  35.         }
  36.         
  37.         // Now we'll add the content
  38.         $font_color $this->generate_image_color($img$this->fontcolor);
  39.         
  40.         //Check to see if 1. content_y is set, if not check if content_before is set and if it is 3. check if content_before_y is set
  41.         // This will determine the y location of the content text
  42.         
  43.         $x $this->content_x;
  44.         
  45.         if ($this->content_y)
  46.             $y $this->content_y;
  47.         else if ($this->content_before)
  48.             $y ($this->content_before_font imagefontheight($this->content_before_font)  imagefontheight($this->font)) $this->content_before_y;
  49.         else
  50.             $y=0;
  51.         
  52.         imagestring($img$this->font$x$y$this->get_latest_entry()$font_color);
  53.         
  54.         // Now finally, add the content after if it is set
  55.         
  56.         if ($this->content_after)
  57.         {
  58.             $content_after_color $this->content_after_fontcolor $this->generate_image_color($img$this->content_after_fontcolor$font_color;
  59.             
  60.             $x $this->content_after_x;
  61.             
  62.             // Either place where it was told to go or place after the main content
  63.             $y $this->content_after_y $this->content_after_y $y imagefontheight($this->font);
  64.             
  65.             imagestring($img$this->content_after_font $this->content_after_font $this->font$x$y$this->content_after$content_after_color);
  66.         }
  67.         
  68.         // Now finally check to see if we need to resample the width and/or height
  69.         
  70.         if ($this->resample_width || $this->resample_height)
  71.         {
  72.             $w $this->resample_width $this->resample_width $this->width;
  73.             $h $this->resample_height $this->resample_height $this->height;
  74.             
  75.             $img2 imagecreatetruecolor($w$h);
  76.             
  77.             imagecopyresampled($img2$img0000$w$h$this->width$this->height);
  78.             imagedestroy($img);
  79.             
  80.             $this->img $img2;
  81.             if ($add_cache)
  82.                 $this->write_to_cache();
  83.                 
  84.                 
  85.             return imagejpeg($img2NULL$this->image_quality);
  86.         }
  87.         $this->img $img;
  88.         
  89.         if ($add_cache)
  90.             $this->write_to_cache();
  91.             
  92.         
  93.         return imagejpeg($imgNULL$this->image_quality);
  94.     }

Parameters:
$check_cache   $check_cache:  boolean If true, cache will be checked to see if an image already exists with same parameters. If one is found, this will be returned.
$add_cache   $add_cache:  boolean If true and an image is not returned after checking the cache, this image will be written to the cache

API Tags:
Return:  binary string of an image
Access:  public


[ Top ]
generate_image_color  [line 753]

  resource generate_image_color( resource $img, string $color  )

Allocates a color to an image for use in the output.

  1. function generate_image_color($img$color)
  2.     {
  3.         $color imagecolorallocate($imghexdec('0x' $color{0$color{1})hexdec('0x' $color{2$color{3})hexdec('0x' $color{4$color{5}));
  4.         return $color;
  5.     }

Parameters:
resource   $img:  an image to allocate a colour to
string   $color:  a hex string

API Tags:
Return:  an allocated image color
Access:  private


[ Top ]
get_from_cache  [line 875]

  void get_from_cache( )

Returns the data from a file in the cache

  1. function get_from_cache()
  2.     {
  3.         // Returns image data from cache
  4.         if (file_exists$this->cache_directory '/' $this->generate_filename() ))
  5.             return file_get_contents$this->cache_directory '/' $this->generate_filename() );
  6.         else 
  7.             return false;
  8.     }


API Tags:
Access:  private


[ Top ]
get_latest_entry  [line 783]

  string get_latest_entry( )

Gets the title of the latest blog entry. Currently this is hardcoded in based on a WordPress RSS feed.

  1. function get_latest_entry()
  2.     {        
  3.         return $this->dynamic_content;
  4.     }


API Tags:
Return:  The title of the latest blog post
Access:  public

Information Tags:
Todo:  Make the data retrieved from the RSS feed configurable. There should be the ability to choose what XML NODE is returned

[ Top ]
is_hex  [line 571]

  bool is_hex( $val $val  )

Checks if a string is hex

  1. function is_hex($val)
  2.     {
  3.         try {
  4.             $this->check_hex($val);
  5.             return true;
  6.         catch (Exception $e{
  7.             return false;
  8.         }
  9.     }

Parameters:
$val   $val:  string'

API Tags:
Return:  true for valid hex, false otherwise
Access:  private


[ Top ]
parse_feed  [line 763]

  void parse_feed( )

Parses the xml returned by $site_feed into $data and $pointers

This is stored for use in get_latest_entry

  1. function parse_feed()
  2.     {
  3.         $this->xml file_get_contents($this->site_feed);
  4.         $this->parser xml_parser_create();
  5.         
  6.         
  7.         if (!xml_parse_into_struct($this->parser$this->xml$this->data$this->pointers))
  8.             throw new Exception('XML document could not be parsed');
  9.         
  10.         xml_parser_free($this->parser);
  11.         $this->xml NULL;
  12.         $this->set_dynamic_content();
  13.     }


API Tags:
Access:  public


[ Top ]
set_background  [line 356]

  void set_background( $val $val  )

Checks a given background to see whether it is a file on the server or

a hexidecimal color value

  1. function set_background($val)
  2.     {
  3.         try {
  4.             $this->background $this->check_hex($val);
  5.         catch (Exception $e{
  6.             if (!preg_match('/(.jpg|.jpeg|.gif|.png)$/i'$val))
  7.             {
  8.                 throw new Exception($e->getMessage(' and is not a valid image');
  9.             }
  10.             if (!file_exists($val))
  11.             {
  12.                 throw new Exception($val ' does not exist on the server');
  13.             
  14.             
  15.             $this->bgdetails getimagesize($val);
  16.             if (!is_array($this->bgdetails|| empty($this->image_functions[strtolower($this->bgdetails['mime'])]))
  17.             {
  18.                 $this->bgdetails false;
  19.                 throw new Exception($val ' is not a valid image, valid images are ' implode', '$this->mime_types));
  20.             }
  21.             
  22.             $this->background $val;
  23.         }
  24.     }

Parameters:
$val   $val:  string relative file on server or hex crgb color string

API Tags:
Access:  public


[ Top ]
set_cache_directory  [line 534]

  void set_cache_directory( $val  )

..

  1. function set_cache_directory($val)
  2.     {
  3.         $this->cache_directory $this->clean_path($val);
  4.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_after  [line 461]

  void set_content_after( $val  )

..

  1. function set_content_after($val)
  2.     {
  3.         if (!is_string($val))
  4.             throw new Exception('content_after must be a string');
  5.         else
  6.             $this->content_after =$val;
  7.             
  8.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_after_font  [line 473]

  void set_content_after_font( $val  )

..

  1. function set_content_after_font($val)
  2.     {
  3.         $this->content_after_font $this->check_font($val);
  4.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_after_fontcolor  [line 481]

  void set_content_after_fontcolor( $val  )

..

  1.     {
  2.         $this->content_after_fontcolor $this->check_hex($val);
  3.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_after_x  [line 489]

  void set_content_after_x( $val  )

..

  1. function set_content_after_x($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('content_after_x must be a number');
  5.         else
  6.             $this->content_after_x $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_after_y  [line 500]

  void set_content_after_y( $val  )

..

  1. function set_content_after_y($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('content_after_y must be a number');
  5.         else
  6.             $this->content_after_y $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_before  [line 409]

  void set_content_before( $val  )

..

  1. function set_content_before($val)
  2.     {
  3.         if (!is_string($val))
  4.             throw new Exception('content_before must be a string');
  5.         else
  6.             $this->content_before =$val;
  7.             
  8.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_before_font  [line 421]

  void set_content_before_font( $val  )

..

  1. function set_content_before_font($val)
  2.     {
  3.         $this->content_before_font $this->check_font($val);
  4.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_before_fontcolor  [line 429]

  void set_content_before_fontcolor( $val  )

..

  1.     {
  2.         $this->content_before_fontcolor $this->check_hex($val);
  3.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_before_x  [line 437]

  void set_content_before_x( $val  )

..

  1. function set_content_before_x($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('content_before_x must be a number');
  5.         else
  6.             $this->content_before_x $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_before_y  [line 448]

  void set_content_before_y( $val  )

..

  1. function set_content_before_y($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('content_before_y must be a number');
  5.         else
  6.             $this->content_before_y $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_x  [line 384]

  void set_content_x( $val  )

..

  1. function set_content_x($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('content_x must be a number');
  5.         else
  6.             $this->content_x $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_content_y  [line 395]

  void set_content_y( $val  )

..

  1. function set_content_y($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('content_y must be a number');
  5.         else
  6.             $this->content_y $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_dynamic_content  [line 788]

  void set_dynamic_content( )


API Tags:
Access:  public


[ Top ]
set_font  [line 338]

  void set_font( $val  )

..

  1. function set_font($val)
  2.     {                
  3.         $this->font $this->check_font($val);
  4.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_fontcolor  [line 346]

  void set_fontcolor( $val  )

..

  1. function set_fontcolor($val)
  2.     {
  3.         $this->fontcolor $this->check_hex($val);
  4.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_height  [line 327]

  void set_height( $val  )

..

  1. function set_height($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('Height is not a valid number');
  5.         else
  6.             $this->height $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_image_quality  [line 544]

  void set_image_quality( $val $val  )

Sets the value of $image_quality... uses default value if not an int 1-100

Parameters:
$val   $val:  int output quality of the image

API Tags:
Access:  public


[ Top ]
set_resample_height  [line 522]

  void set_resample_height( $val  )

..

  1. function set_resample_height($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('Resample Height must be a number');
  5.         else 
  6.             $this->resample_height $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_resample_width  [line 511]

  void set_resample_width( $val  )

..

  1. function set_resample_width($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('Resample Width must be a number');
  5.         else 
  6.             $this->resample_width $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
set_site_feed  [line 305]

  void set_site_feed( $url  )

..

  1. function set_site_feed($url)
  2.     {
  3.         if (!$this->check_feed_validity($url))
  4.             throw new Exception('Site feed is either not a valid URL or does not address a valid XML file');
  5.         else
  6.             $this->site_feed $url;
  7.     }

Parameters:
   $url: 

API Tags:
Access:  public


[ Top ]
set_width  [line 316]

  void set_width( $val  )

..

  1. function set_width($val)
  2.     {
  3.         if (!is_numeric($val))
  4.             throw new Exception('Width is not a valid number');
  5.         else
  6.             $this->width $val;
  7.     }

Parameters:
   $val: 

API Tags:
Access:  public


[ Top ]
write_to_cache  [line 841]

  void write_to_cache( )

Takes the image resource in $img and writes it to cache/filename.jpg.

Runs clear_cache() if dynamic content has changed

  1. function write_to_cache()
  2.     {
  3.         // Check if image has been written yet
  4.         if (!$this->img || !is_resource($this->img))
  5.         {
  6.             $this->generate_image();
  7.         }
  8.         
  9.         // Throw an exception if we still don't have an image
  10.         if (!is_resource($this->img))
  11.         {
  12.             throw new Exception('Could not write to cache as image could not be generated');
  13.         }
  14.         // Check to see if the content has changed at all
  15.         $write_file true;
  16.         if (file_exists($this->cache_directory '/' 'latest-content.txt'))
  17.         {
  18.             if (file_get_contents($this->cache_directory '/' 'latest-content.txt'!= $this->get_latest_entry())
  19.                 $this->clear_cache();
  20.             else 
  21.                 $write_file false;
  22.                 
  23.         }
  24.         imagejpeg($this->img$this->cache_directory '/' $this->generate_filename()100);
  25.         
  26.         if ($write_file{
  27.             $file fopen($this->cache_directory '/' 'latest-content.txt''w');
  28.             fwrite($file$this->get_latest_entry());
  29.         }
  30.     }


API Tags:
Access:  public


[ Top ]

Documentation generated on Sat, 08 Nov 2008 00:52:55 +1100 by phpDocumentor 1.4.1