• 0

RSS Feed Based Signature


Question

At the moment, in my signature I have the news from my blog, powered by Feedburner. I like how it works, but I think it is a bit too ugly and cumbersome to look nice in a signature. So, I've had an idea that someone might be able to do for me, or even make a site that will do it automatically:

So my feed URL is:

http://www.tim-rogers.co.uk/cutenews/rss.php

and I want to create a signature that shows the title of the latest post made on the blog. If the title is over a certain chracter limit, the ending wil be cut off and replaced with "..."

Here is the template I have created

trbfeedsigsample2tq.png

Can anyone do this?

Link to comment
https://www.neowin.net/forum/topic/348102-rss-feed-based-signature/
Share on other sites

18 answers to this question

Recommended Posts

  • 0

So you just want the one title, no animation?

If you have GD installed on your server, its relatively easy.

(I will write something that should work in PHP for you and reply. - I can do it faster in ASP.net and some other languages but it looks like your running PHP).

I haven't written PHP for a while and don't have it installed, so it MAY work, but i'm pretty sure that i can get something thats close to working at least, or gives the general idea of how you'd do it.

  • 0

Yah, im in the middle of writing it. I can't test it though, because i don't have PHP installed.

To test for gd i think you just have to make a new page with this:

<?php
php_info():
?>

It should list gd somewhere on it "i think there is a section where it lists php component configurations"

  • 0

Heres how you get the title from your feed: (you can also use xml functions for this)

$feedurl = "http://www.tim-rogers.co.uk/cutenews/rss.php"; //can also be local url
$fp = fopen(,"r"); //open the feed
$contents = fread($fp,filesize($feedurl));
fclose($fp);

preg_match("<item>\s*<title>\s*(.*?)\s*</title></item>",$contents,$matchdata); //matches a regular expression for the title
$title = $matchdata[1];

Oh yah, i realized that the code is different for GD2 and plain old GD. So try to find out which one your running.

Also tell me if there are any problems with this code. Try printing $title after it.

  • 0

Well the idea is to take the background image and just throw the text on top.

I can do this for you.

I guess i probably should install php on my computer anyways because its useful and just write the whole thing and attach it, but i would still need to know what version of gd you have.

To find this out:

1. Download attached file

2. Rename it as phpinfo.php

3. Upload it to your server

4. Run it to find out your gd version or send the url to me.

php_info.txt

  • 0

Heres my little script: (also attached as .txt file, rename as .php>

There are a number of variables that are editable, mentioned at the top.

<? 
// editable:
// $feedurl - the url of your feed
// $imageurl - your background image (if not png change imagecreatefrompng to imagecreatefromgif or other types)
// $fontcolor - the font color
// $fontsize - the font size
// $font - the ttf font file path ex: 'arial.ttf'
// $x - the x position of text
// $y - the y position of text
// $angle - text angle

$feedurl = "http://www.tim-rogers.co.uk/cutenews/rss.php";

$fp = fopen($feedurl,"r");
$contents = ".";
while (!feof($fp))
	$contents .= fread($fp,8192);
fclose($fp);

preg_match("#<rss.*?>.*?<channel.*?<item>\s*<title>\s*(.*?)\s*<\/title>#s",$contents,$matchdata);
$title = $matchdata[1];

$imageurl = "http://img348.imageshack.us/img348/7508/trbfeedsigsample2tq.png";

$img = imagecreatefrompng($imageurl);

$font = 'arial.ttf';
$fontcolor = imagecolorallocate($img, 255, 255, 255);
$fontsize = 8;
$x = 65;
$y = 16;
$angle = 0;

imagettftext($img,$fontsize,$angle,$x,$y,$fontcolor,$font,$title);

header('Content-type: image/png');
imagepng($img);
?>

rss.txt

  • 0

Nice job benjeeeboy, can I use it too?

Edit: Can't get it working. :/ Here's my code:

<? 
// editable:
// $feedurl - the url of your feed
// $imageurl - your background image (if not png change imagecreatefrompng to imagecreatefromgif or other types)
// $fontcolor - the font color
// $fontsize - the font size
// $font - the ttf font file path ex: 'arial.ttf'
// $x - the x position of text
// $y - the y position of text
// $angle - text angle

$feedurl = "http://blog.mynimal.net/?feed=rss2";

$fp = fopen($feedurl,"r");
$contents = ".";
while (!feof($fp))
	$contents .= fread($fp,8192);
fclose($fp);

preg_match("#<rss.*?>.*?<channel.*?<item>\s*<title>\s*(.*?)\s*<\/title>#s",$contents,$matchdata);
$title = $matchdata[1];

$imageurl = "http://www.mynimal.net/feed.png";

$img = imagecreatefrompng($imageurl);

$font = 'arial.ttf';
$fontcolor = imagecolorallocate($img, 255, 255, 255);
$fontsize = 8;
$x = 65;
$y = 16;
$angle = 0;

imagettftext($img,$fontsize,$angle,$x,$y,$fontcolor,$font,$title);

header('Content-type: image/png');
imagepng($img);
?>

Using Wordpress, all the files are there. Here's the URL:

http://www.mynimal.net/feed.php

Edited by mynimal
  • 0

I prefer asp.net as a development language. Image output is much easier in it. If you would like, I could work up a signature using that. I do most of my development now on ASP.NET 2.0 but as its still in beta, 1.1 is probably better for something that will be deployed by other people.

I think i'll take a stab at it tommarow.

Edited by benjeeeboy
  • 0

mynimal, feel free to use it.

The reason your feed didn't show was that for whatever reason, your image didn't fit valid php spec (right clicking on it in firefox shows this too under alt).

I opened the image in PS and resaved it and it worked. Try the attached version

post-23893-1122173608.png

  • 0

That looks really good.

I just realized though that if the title in the feed is greater than a certain length (in pixels), it will just run off the edge of the image, while it really should do a ... thing at the end.

I also thought of a few extra options that may be good to add. I will probably post another soon, and asp.net version a little later.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.