Help - Search - Members - Calendar
Full Version: RSS Image Signature
Neowin Forums > Help & Discussion Center > Software Discussion & Assistance > Software created by our members
benjeeeboy
I created an image signature in that grabs the title of the latest post in your rss feed.

NOTE: They work well, but aren't close to production quality so don't expect that yet

PHP & GD2 Version: [attachmentid=134392] (rename as .php and open it in a text editor to configure it)

ASP.NET Version: [attachmentid=134213] (setup in iis, configure in web.config and run Default.aspx)

Original Topic
yodat
Is/Will there be an animated version of this script like Apple's Hot News Ticker Bar ?

user posted image

http://www.apple.com/

Btw, Thanks for the script smile.gif
benjeeeboy
I plan on eventually doing animated gifs.

The setback for this is that there doesn't seem to be a built in way in PHP/GD or ASP.NET to do this. It may be easier in PHP w/ ImageMagick, but i haven't looked into that. Even if it isn't built in, it should be possible to hack it together by generating multiple frames, and then putting those together into an animated gif.

Another alternative, is to generate SWF through Ming (I believe that there is something similar in asp.net).
benjeeeboy
I think i did find an easy way to do gif animation in asp.net, so that will probably come sooner than the php one.
[bear]
this is pretty neat, nice job!
TimRogers
I got mine going smile.gif Thanks!
benjeeeboy
I created an ASP.NET version. It still needs alot of work, but its a start.
(download in first post)

Oh yah, TimRogers, the link in your sig is to the old topic wink.gif
Alex Suraci
Awesome job. biggrin.gif

Edit:

QUOTE
Parse error: parse error, unexpected T_NEW in /www/g/gfxutopianet/htdocs/feed.php on line 48


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

Line 48:

CODE
throw new Exception();
benjeeeboy
mynimal, I'm not exactly sure why yours doesn't work. My configuration looks like this: (a.jpg is just my copy of your image)
CODE

$feedurl = "http://blog.mynimal.net/?feed=rss2";
$imageurl = "a.png";
$imageinputtype = 'png';
$imageoutputtype = 'png';
$problemwithfeedtext = 'Problem loading feed';
$problemwithimagetext = 'Problem loading image';
$font = 'arial.ttf';
$fontcolor = array(255,255,255); //array (r,g,b)
$fontsize = 12;
$fontantialiased = TRUE;
$x = 65;
$y = 16;
$angle = 0;
$maxwidth = NULL;
$maxheight = NULL;
$toofarstr = '...';

If this doesn't work for you, then could you tell me your version of PHP & GD?
TimRogers
Just done one for the Neowin forum RSS, will you repost the old script, as I find it easier to use, as there aren't so many options!

user posted image

Bare in mind I did this one in Paint tongue.gif

I've just seen an error on it now, if the feed contains an invalid character - like to "&" a minute ago, it showed up as &amp tongue.gif
benjeeeboy
Pretty cool but it goes of the edge, which i corrected in the new one.

Yah, the script configuration is pretty complicated so i'll try to group the options together and show which ones are more important.

I like the idea of the designer -- i will probably try to make one.

Yah, the & error is a problem in alot of applications that use rss feeds (open a feed in firefox with a & in it and it will show it like that too), but i can fix that relatively easily. The problem is that i think that there are alot of characters that show up like that and it may cause the script to slow down if i try to elimate all of them.

The other thing i was thinking about is whether there is a good way to make it easy to link the image to the post that it is showing the title for. I can think of a bunch of ways, but none of them are very good.
Alex Suraci
QUOTE(benjeeeboy @ Jul 24 2005, 14:15)
mynimal, I'm not exactly sure why yours doesn't work.  My configuration looks like this: (a.jpg is just my copy of your image)
CODE

$feedurl = "http://blog.mynimal.net/?feed=rss2";
$imageurl = "a.png";
$imageinputtype = 'png';
$imageoutputtype = 'png';
$problemwithfeedtext = 'Problem loading feed';
$problemwithimagetext = 'Problem loading image';
$font = 'arial.ttf';
$fontcolor = array(255,255,255); //array (r,g,b)
$fontsize = 12;
$fontantialiased = TRUE;
$x = 65;
$y = 16;
$angle = 0;
$maxwidth = NULL;
$maxheight = NULL;
$toofarstr = '...';

If this doesn't work for you, then could you tell me your version of PHP & GD?
[right][snapback]586264454[/snapback][/right]

I'm beginning to think it's my host that's the problem.

I mean, look at this:
http://www.mynimal.net/rss/info.php

PHP version is 5.0.4 and 4.?.?, GD is er..guessing GD2? Not sure.
benjeeeboy
QUOTE(mynimal @ Jul 24 2005, 19:48)
I'm beginning to think it's my host that's the problem.

I mean, look at this:
http://www.mynimal.net/rss/info.php

PHP version is 5.0.4 and 4.?.?, GD is er..guessing GD2? Not sure.
[right][snapback]586264610[/snapback][/right]

I test it with php 5.04 and the latest version of GD2. I don't really see what could be going wrong because that sounds like a php problem, but since your usure about the gd version, i think checking that out is the best route to go.
Make a new .php file with <? phpinfo(); ?> inside to find out.

I also did some slight updates to the code:
-better organization for options
-option to fix the &amp; and &quot; that sometimes show up

I'm done with updating this today, and plan to do the designer thing sometime.
Alex Suraci
QUOTE(benjeeeboy @ Jul 24 2005, 15:24)
I test it with php 5.04 and the latest version of GD2.  I don't really see what could be going wrong because that sounds like a php problem, but since your usure about the gd version, i think checking that out is the best route to go.
Make a new .php file with <? phpinfo(); ?> inside to find out.
[right][snapback]586264748[/snapback][/right]

That's what this is, and what leads me to conclude that my host is having problems. :\

EDIT: Nevermind. I messefd it up, now the phpinfo is working..

GD Version bundled (2.0.28 compatible)
benjeeeboy
It is likely that it is your host, as the way php acts is controlled by a configuration file, not usually exposed to the host's clients. Despite this, sometimes there are workarounds or ways to temporary change values in the configuration.
Its probably possible to figure out a fix.

I know you said it was on line 48, but i don't have a copy of that version anymore. Could you send me line 48 so i can see what it is?
Alex Suraci
QUOTE(benjeeeboy @ Jul 24 2005, 16:14)
It is likely that it is your host, as the way php acts is controlled by a configuration file, not usually exposed to the host's clients.  Despite this, sometimes there are workarounds or ways to temporary change values in the configuration. 
Its probably possible to figure out a fix.

I know you said it was on line 48, but i don't have a copy of that version anymore.  Could you send me line 48 so i can see what it is?
[right][snapback]586264941[/snapback][/right]

Line 48 is "throw new Exception();", and deals with the error reporting.
benjeeeboy
I'm working on trying to figure out the cause of that, but as long as your configuration is ok, you should be able to remove that line.
TimRogers
Would you make the version with the cut off so it works with my current Neowin RSS one, as my blog titles are never too long, yet the Neowin ones are? Here is the current code, could you add the cutoff to it, as I don't understand all the options on the new version tongue.gif

CODE
<?
// ******************************************************
//          RSS Feed Script by Benjeeboy on Neowin
//              Version Customized by TimRogers
//         Shows you the latest forum posts on Neowin
// ******************************************************
// 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.neowin.net/backend.php?page=forum";

$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.tim-rogers.co.uk/neowinforum/template.PNG";

$img = imagecreatefrompng($imageurl);

$font = 'seguibd.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);
?>


Alex Suraci
Tried TimRogers' Neowin version, and that one works (On my server). But, when I change it to my wordpress blog RSS, it doesn't work?
benjeeeboy
Mynimal, does your feed validate? Also, did you try to take out the "throw new Exception();" line that was causing the problem?

TimRogers, what confuses you about it the new version? - so i can improve it. The options are nearly identical which is why im unsure of why you don't like them. Heres a modified old version with the cut off as per request:
CODE

<?
// ******************************************************
//          RSS Feed Script by Benjeeboy on Neowin
//              Version Customized by TimRogers
//         Shows you the latest forum posts on Neowin
// ******************************************************
// 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
// $maxwidth - the number of pixels of text to display

$feedurl = "http://www.neowin.net/backend.php?page=forum";

$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.tim-rogers.co.uk/neowinforum/template.PNG";

$img = imagecreatefrompng($imageurl);

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

$end='';
$toofarstr='...';
$textbounds = imagettfbbox($fontsize,$angle,$font,$title);
if ($maxwidth != NULL)  // if its not -1, make it fit width-wise
{
while ( $textbounds[2] - $textbounds[0] > $maxwidth ) //it is wider than maxwidth
{
 
 $title = substr($title,0,strlen($title)-1); // remove last character
 $end = $toofarstr;
 $textbounds = imagettfbbox($fontsize,$angle,$font,$title . $end);
}
}

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

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


Anyways, i plan on rewriting alot of it, because as it is i can't do much with it.
Alex Suraci
QUOTE(benjeeeboy @ Jul 25 2005, 21:29)
Mynimal, does your feed validate? Also, did you try to take out the "throw new Exception();" line that was causing the problem?

I took out that line (new version) and all hell broke loose. tongue.gif I also tried removing all instances of the error reporting.

Also, I tried TomRoger's neowin script on my host. It works with the Neowin RSS but not mine.

P.S. It's valid.

//Edit: I just tried another wordpress RSS feed from another blog and I got the same error. It seems to be some sort of Wordpress bug.
TimRogers
Thats what I was thinking, it's a bug in the Wordpress RSS that means that the code can't find what it's looking for! Thanks for the code, I'll get it ready...
Alex Suraci
benjeeboy: Could you possibly see if you could get a wordpress version going? I've uploaded the RSS code:

http://junk.mynimal.net/uploads/wp-rss2.rar
benjeeeboy
My new version is going to be a complete rewrite, and i will try to make it compatible with all feeds and error free.

(Please realise that this is the first time i've written anything in php for ~6 years - when i was 12 so i'm not exactly familiar with it... back then i think it was version 3, now its 5 wink.gif hopefully i'll catch on soon)
benjeeeboy
My new feed loader works with your wordpress page.

To make sure that it agrees with your host, try this test script:
CODE

<?
$domdoc = DOMDocument::load('http://blog.mynimal.net/?feed=rss2');
$xpath = new DOMXPath($domdoc);
$titles = $xpath->query('/*/channel/item/title');
for ($i=0;$i<$titles->length;$i++)
{
 echo $titles->item($i)->nodeValue;
 echo '<br>';
}
?>


It should spit out the titles of your posts
Alex Suraci
Thanks a lot bejeeboy biggrin.gif

Tested the above script, but.. http://www.mynimal.net/rss/rss-feed.php
benjeeeboy
I'm having trouble figuring out what it is. I tried turning on strict error reporting, and it told me one thing that was legal in the language, but not preferred. I changed this, and maybe it fixed the problem.

Try this instead:
CODE

<?
error_reporting(2048);
$domdoc = new DomDocument;
$domdoc->load('http://blog.mynimal.net/?feed=rss2');
$xpath = new DOMXPath($domdoc);
$titles = $xpath->query('/*/channel/item/title');
for ($i = 0; $i < $titles->length; $i++)
{
 echo $titles->item($i)->nodeValue;
 echo '<br>';
}
?>
Alex Suraci
Nope. sad.gif

QUOTE
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /www/g/gfxutopianet/htdocs/rss/rss-feed.php on line 9


Line 9:
CODE
echo $titles->item($i)->nodeValue;
Techy_
Will this code work on PHP4? I was thinking that the 'try { } catch { }' statments was a new thing in PHP5. I might be getting some hosting in the next few weeks and wanted to use this but they only use PHP4 where I'll be getting hosting.

Cheers,
-Techy
benjeeeboy
I have absolutely no idea if it will work on PHP4. In my newer version that I am working on now, i will try to not use exceptions, so it may be compatible. I am just re-learning php now, so it may take a bit to get everything working perfectly but i will add php4 compatibility to my todo list.
benjeeeboy
I added a bunch to the test code (please post the results). Maybe this will give more insight into whats wrong so i can fix this and get and moving on the new version.
CODE

<?
$domdoc = new DomDocument;
$domdoc->load('http://blog.mynimal.net/?feed=rss2');
$xpath = new DOMXPath($domdoc);
$titles = $xpath->query('/*/channel/item/title');
echo "Number of entries: ";
echo $titles->length;
echo "<br>";
for ($i = 0; $i < $titles->length; $i++)
{
 $itemnode = $titles->item($i);
 echo $itemnode->nodeName;
 echo ": ";
 echo $itemnode->nodeValue;
 echo '<br>';
}
echo "<p>";
echo "other way:";
echo "<br>";
$itemlist = $domdoc->getElementsByTagName('item');
echo "num items: ";
echo $itemlist->length;
echo "<br>";
for ($j=0;$j<$itemlist->length;$j++)
{
 $item = $itemlist->item($j);
 $itemtitles = $item->childNodes;
 for ($k=0;$k<$itemtitles->length;$k++)
 {
  if ($itemtitles->item($k)->nodeName=='title')
  {
   echo $itemtitles->item($k)->nodeValue;
   echo '<br>';
  }
 }
}
?>


Thank you for helping me help you.
Alex Suraci
QUOTE(benjeeeboy @ Jul 27 2005, 21:53)
I added a bunch to the test code (please post the results).  Maybe this will give more insight into whats wrong so i can fix this and get and moving on the new version.

Thank you for helping me help you.
[right][snapback]586283921[/snapback][/right]

Same error as before. sad.gif
QUOTE
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /www/g/gfxutopianet/htdocs/rss/rss-feed.php on line 30


Line 30:
CODE
  if ($itemtitles->item($k)->nodeName=='title')
TimRogers
Your RSS dosen't like this system tongue.gif
StevoFC
mine gets the same error.
benjeeeboy
I must have a special version of php then. That really helps with trying to make this wink.gif I don't really have much time now anyways. I may get back to it later.
Alex Suraci
Thank you for your hard work, benjeeeboy. smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.