* @copyright (C) 2003-2005 by the authors * @version 1.1 */ /** * defines the source where to get the rss feed from! * NOTE! This need allow_url_fopen to be on, if the file is an url. */ define( 'RSS_SOURCE' , 'http://feeds.feedburner.com/BlogrodentRichTatumsWeblog'); /** * defines the width of the image */ define( 'IMAGE_WIDTH' , 400 ); /** * define the height of the image */ define( 'IMAGE_HEIGHT', 70 ); /** * defines the font to be used, please note you must upload your own font file */ define( 'TEXT_FONT', './tahoma.ttf'); /** * defines the headline to be displayed, you can turn this off by setting the * headline to '' */ define( 'TEXT_HEADLINE' , 'BlogRodent: Pentecostal Rumination & Review - Latest Headlines' ); /** * defines the font size of the headline */ define( 'TEXT_HEADLINE_SIZE' , 10 ); /** * defines if the headline should be underlined */ define( 'TEXT_HEADLINE_UNDERLINE', true ); /** * defines the amount of lines to be displayed from the feed */ define( 'MAX_LINES' , 3 ); /** * defines the font size of the displayed lines */ define( 'TEXT_SIZE' , 8 ); /** * defines the indent of the lines to the left border of the image */ define( 'LINE_INDENT', 10 ); /** * defines where the column one starts */ define( 'COLUMN_1' , 0 ); /** * defines where the column two starts */ define( 'COLUMN_2' , 50 ); /****************************************************************************** YOU SHOULDN'T CHANGE ANYTHING BELOW HERE, UNLESS YOU KNOW WHAT YOU ARE DOING! ******************************************************************************/ // // instanctiate new signature object // $sig = &new RSS_PNG_Signature( RSS_SOURCE, IMAGE_WIDTH, IMAGE_HEIGHT ); // // configure signature according to defines above // $sig->setFont ( TEXT_FONT ); $sig->setHeadline( TEXT_HEADLINE, TEXT_HEADLINE_SIZE, TEXT_HEADLINE_UNDERLINE ); $sig->setBody ( MAX_LINES, TEXT_SIZE, LINE_INDENT, array(COLUMN_1, COLUMN_2) ); // // load the feed and return the image // $sig->loadFeed(); $image = $sig->getImage(); // // display the image // header("Content-type: image/png"); imagepng($image); /** * this class implements a rss feed to image converter * * This class doesn't relay on external xml parser, and is really stupid * * @author Martin Burchert * @copyright (C) 2003-2005 by the authors * @version 1.0 */ class RSS_PNG_Signature { /**#@+ * private attributes * * @access private */ var $_image; var $_imageWidth; var $_imageHeight; var $_imageFont; var $_imageHead; var $_imageHeadSize; var $_imageHeadLine; var $_imageBodyLines; var $_imageBodySize; var $_imageBodyIndent; var $_imageBodyCols; var $_rssFeed; var $_rssArray; var $_xmlInItem; var $_xmlCurElement; var $_xmlIndexNo; var $_xmlParser; /**#@-*/ /** * Class Constructor * * @param string $rssFeedPath the path to the rss feed * @param integer $width the width of the image * @param integer $height the height of the image * @return RSS_PNG_Signature */ function RSS_PNG_Signature( $rssFeedPath, $width, $height ) { $this->_imageWidth = $width; $this->_imageHeight = $height; $this->_imageFont = ''; $this->_image = imagecreate( $width, $height ); $this->_imageHead = ''; $this->_imageHeadSize = 8; $this->_imageHeadLine = false; $this->_imageBodyLines = 3; $this->_imageBodySize = 8; $this->_imageBodyIndent = 10; $this->_imageBodyCols = array(0,50); $this->_rssFeedPath = $rssFeedPath; $this->_rssArray = array(); $this->_xmlInItem = false; $this->_xmlCurElement = ''; $this->_xmlIndexNo = 0; $this->_xmlParser = xml_parser_create(); xml_set_object( $this->_xmlParser, $this ); xml_set_element_handler($this->_xmlParser, '_xmlOpenTag', '_xmlCloseTag'); xml_set_character_data_handler( $this->_xmlParser, '_xmlGetData' ); } /** * loads the feed and parses it using the php internal xml parser * * @access public */ function loadFeed() { $rssData = implode('', file( RSS_SOURCE ) ); xml_parse( $this->_xmlParser, $rssData ); } /** * sets some options for the headline of the image * * @access public * * @param string $text the headline text to be displayed * @param integer $fontSize the fonsize of the headline text * @param boolean $underline if the headline should be underlined or not */ function setHeadline( $text, $fontSize, $underline = false ) { $this->_imageHead = $text; $this->_imageHeadSize = $fontSize; $this->_imageHeadLine = $underline; } /** * sets some options for the body of the image * * @access public * * @param integer $maxLines the maximum numbers of lines to be displayed * @param integer $fontSize the fontsize of the body text * @param integer $indent the indent of the text from the left border * @param array $cols the columns startpoints for each text column */ function setBody( $maxLines, $fontSize, $indent, $cols ) { $this->_imageBodyLines = $maxLines; $this->_imageBodySize = $fontSize; $this->_imageBodyIndent = $indent; $this->_imageBodyCols = $cols; } /** * sets the font to be used in this image * * @access public * * @param string $font path to the fontfile to be used */ function setFont( $font ) { $this->_imageFont = $font; } /** * creates the image and returns the image ressource identifier to the image * * @access public * * @return resource */ function getImage() { $colBG = imagecolortransparent($this->_image, imagecolorallocate($this->_image, 252, 242, 228)); $colBlack = imagecolorallocate($this->_image, 205, 129, 24); $curY = 0; $curX = 0; // Draw Headline, if headline text exists if ( $this->_imageHead != '' ) { $curY += imagefontheight( $this->_imageHeadSize ); imagettftext ( $this->_image, $this->_imageHeadSize, 0, $curX, $curY, $colBlack, $this->_imageFont, $this->_imageHead ); if ( $this->_imageHeadLine ) { imageline( $this->_image, 0, $curY+1, $this->_imageWidth, $curY+1, $colBlack ); } } $count = 1; $item = reset( $this->_rssArray ); while ( $count <= $this->_imageBodyLines ) { // Move draw position down by size of the font $curY += imageFontHeight( $this->_imageBodySize ); // Reset X position $curX = 0; // Find new X position $curX = $this->_imageBodyIndent + $this->_imageBodyCols[0]; // write text imagettftext( $this->_image, $this->_imageBodySize, 0, $curX, $curY, $colBlack, $this->_imageFont, $item['date'] ); // move x on $curX += $this->_imageBodyCols[1]; // write text imagettftext( $this->_image, $this->_imageBodySize, 0, $curX, $curY, $colBlack, $this->_imageFont, $item['title'] ); $count++; $item = next( $this->_rssArray ); } return $this->_image; } /** * handler method of the xml parser for opening tags * * @access private * * @param resource $parser a reference to the XML parser calling the handler * @param string $name the name of the element for which this handler is called * @param array $param an associative array with the element's attributes */ function _xmlOpenTag( $parser, $name, $param ) { if ( $name == 'ITEM' ) { $this->_xmlInItem = true; $this->_xmlIndexNo++; } else { $this->_xmlCurElement = $name; } } /** * handler method of the xml parser for closing tags Enter description here... * * @access private * * @param resource $parser a reference to the XML parser calling the handler * @param string $name the name of the element for which this handler is called */ function _xmlCloseTag( $parser, $name ) { if ( $name == 'ITEM' ) { $this->_xmlInItem = false; } else { $this->_xmlCurElement = ''; } } /** * the character data handler method for the XML parser * * @access private * * @param resource $parser a reference to the XML parser calling the handler * @param string $data the character data as a string */ function _xmlGetData( $parser, $data ) { if ( $this->_xmlInItem && $this->_xmlCurElement == 'TITLE' ) { $this->_rssArray[ $this->_xmlIndexNo ][ 'title' ] = $data; } elseif ( $this->_xmlInItem && $this->_xmlCurElement == 'PUBDATE' ) { $date = $data; $date = split(' ', $date); $date = '['.$date[2].'/'.$date[1].']'; $this->_rssArray[ $this->_xmlIndexNo ][ 'date' ] = $date; } } } ?>