Created
August 6, 2008 15:14
-
-
Save geoffgarside/4222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a background image and RSS feed titles from the RSS feed will be overlaid on the background image. | |
This code is in the Public Domain. | |
Originally developed at http://forum.osnn.net/showthread.php?t=52418 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Code is in the Public Domain. | |
// Author: Geoff Garside | |
// URL: http://gist.github.com/4222 | |
// Image Configuration | |
$image_filename = "background.png"; // Path to background image | |
$image_fontfile = "verdana.ttf"; // Path to font file | |
$text_font_size = 10; // Size in Points | |
$text_left_shift = 5; // Number of pixels from the left to place the text | |
$text_top_shift = 60; // Number of pixels from the top to place the text | |
$text_max_chars = 40; // Maximum number of charaters to show before adding '...' | |
$text_colour_red = 64; // Text colour red value | |
$text_colour_green = 89; // Text colour green value | |
$text_colour_blue = 132; // Text colour blue value | |
// RSS Configuration | |
$rss_feed_url = "http://domain.com/feed.xml"; | |
$number_of_entries = 6; | |
// Go for code | |
$parser = xml_parser_create(); | |
xml_parse_into_struct($parser, | |
file_get_contents($rss_feed_url), $values, $tag_index); | |
$title_tags = array_slice($tag_index['TITLE'], 1, $number_of_entries); | |
// Image Creation | |
$imgData = getimagesize($image_filename); | |
header("Content-type: {$imgData['mime']}"); | |
$output = ''; | |
switch($imgData[2]) { | |
case IMAGETYPE_GIF: | |
$im = ImageCreateFromGIF($image_filename); | |
$output = create_function('$im', 'ImageGIF($im);'); | |
break; | |
case IMAGETYPE_JPEG: | |
$im = ImageCreateFromJPEG($image_filename); | |
$output = create_function('$im', 'ImageJPEG($im, "", 100);'); | |
break; | |
case IMAGETYPE_PNG: | |
$im = ImageCreateFromPNG($image_filename); | |
ImageAlphaBlending($im, false); | |
$output = create_function('$im', 'ImageSaveAlpha($im, true); ImagePNG($im);'); | |
break; | |
default: | |
die ("Unsupported Image Type"); | |
} | |
$black = ImageColorAllocate($im,0,0,0); | |
$text_colour = ImageColorAllocate($im, | |
$text_colour_red, $text_colour_green, $text_colour_blue); | |
$vertical_offset = 0; | |
foreach ($title_tags as $i) { | |
if (strlen($values[$i]['value']) > $text_max_chars) { | |
$title = substr($values[$i]['value'], 0, $text_max_chars - 5) . "..."; | |
} else { | |
$title = $values[$i]['value']; | |
} | |
ImageTTFText($im, $text_font_size, 0, | |
$text_left_shift, $text_top_shift + $vertical_offset, | |
$text_colour, $image_fontfile, $title); | |
$vertical_offset += 12; | |
} | |
$output($im); | |
ImageDestroy($im); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment