Making A Custom Feedburner Subscriber Counter

Posted 1 week, 6 days ago at 11:01 pm. 2 comments

So it’s fairly late here in the UK but I thought I’d do a quick tutorial on how to make a custom subscriber counter for you Feedburner feed. Usually you get one that looks something like this:

Not especially pretty but nice enough for most people. However what if you want to give a little bit of pazazz to it… Wow, did I just use the word pazazz! Damn.

So anyway here’s how to do it using PHP5 & GD. Please make sure you have GD installed on your server using phpinfo() before trying this. If you don’t have it either ask your system admin if they can install it for you, or if you run the server install it yourself.

Before we start here is what it can look like once it’s done. This is from my other blog, Celeb ‘O Rama:

Feedburner Subscriber Count

You can make it look however you want but that one matches Celeb ‘O Rama in style. K, so here we go.

I’m going to use a PNG image but I would think it would work with jpegs too with a little bit of a switch around. Anyway first off, get the image you would like to use without any text on but use an image editor to line up some text in a font of your choosing to see how it looks.

Now we have the image let’s start the PHP script. Start off with a header to let the browser know we are giving it an image.

1
header("Content-type: image/png");

Next we load in our background image:

2
$img = imagecreatefrompng("subscribe.png");

If you are using a jpeg then change the last two lines to have jpeg, yes with the ‘e’, instead of png. Next we can allocate some colors for our text. I’m going to make two since I’m making a shadow as well.

3
4
$color = imagecolorallocate($img, 255, 255, 255);
$color2 = imagecolorallocate($img, 20, 20, 20);

Now we load our Feedburner awarness API’s XML file using simpleXML. This requires that you have PHP5. There is a way to do it using PHP4 using the old XML parser but it’s very clunky and impractical for what we are doing. Change ‘celeb-o-rama’ for whatever is on the end of your Feedburner URL.

5
$xml = simplexml_load_file('http://api.feedburner.com/awareness/1.0/GetFeedData?uri=celeb-o-rama') or die ('Couldn\'t load XML file!');

Next we get our feedcount.

6
$feedCount = $xml->feed->entry['circulation'];

Now you will need to get the font you decided on and copy it. Then upload this copy into the same directory as this PHP script. We will tell GD what it’s called now. I used impact, and it doesn’t matter it it’s a true type or open type font as long as the file extension is .ttf it should be fine.

7
$font = 'impact.ttf';

Next set your lines of text. I’m going to use three.

8
9
10
$line1 = "$feedCount readers";
$line2 = 'subscribed here.';
$line3 = 'Subscribe today!';

Now we use the imagettftext() function to place our text on the image. Using the function goes something like this, and yes all parts are required. imagettftext(image handle, font size, angle, x_pos, y_pos, color, font, text);.

11
12
13
14
15
16
imagettftext($img, 16, 0, 69, 22, $color2, $font, $line1);
imagettftext($img, 16, 0, 68, 22, $color, $font, $line1);
imagettftext($img, 16, 0, 69, 43, $color2, $font, $line2);
imagettftext($img, 16, 0, 68, 43, $color, $font, $line2);
imagettftext($img, 16, 0, 73, 72, $color2, $font, $line3);
imagettftext($img, 16, 0, 72, 72, $color, $font, $line3);

The first one is the shadow, then the next is the white text. Finally we ‘make’ the image and then destroy the handle to stop memory waste, etc.

17
18
imagepng($img);
imagedestroy($img);

Here is the whole script, with comments, in one text box for those who want to copy and paste.

header("Content-type: image/png");
 
// Load the PNG file
$img = imagecreatefrompng("subscribe.png");
 
// Set 2 text colors, one for a shadow (Handle, RGB)
$color = imagecolorallocate($img, 255, 255, 255);
$color2 = imagecolorallocate($img, 20, 20, 20);
 
// Load Feedburner Awareness API
$xml = simplexml_load_file("http://api.feedburner.com/awareness/1.0/GetFeedData?uri=celeb-o-rama") or die ('Couldn\'t load XML file!');
 
// Load Feedcount
$feedCount = $xml->feed->entry['circulation'];
 
// Set our font (Use ttf only)
$font = 'impact.ttf';
 
// Set our text
$line1 = "$feedCount readers";
$line2 = 'subscribed here.';
$line3 = 'Subscribe today!';
 
// imagettftext(Img Handle, Text Size, Text Angle, X_pos, Y_pos, Color var, ttf Font var, Text var);
imagettftext($img, 16, 0, 69, 22, $color2, $font, $line1);
imagettftext($img, 16, 0, 68, 22, $color, $font, $line1);
imagettftext($img, 16, 0, 69, 43, $color2, $font, $line2);
imagettftext($img, 16, 0, 68, 43, $color, $font, $line2);
imagettftext($img, 16, 0, 73, 72, $color2, $font, $line3);
imagettftext($img, 16, 0, 72, 72, $color, $font, $line3);
 
//'create' our image for the browser, then destroy the handle.
imagepng($img);
imagedestroy($img);

The background image, script and ttf font should all be uploaded into the same folder, although you can place the font and image in different folders I wouldn’t advise it. Oh and for those looking for accurate font sizes, the font size is in pixels or points depending on whether you are using GD1 or GD2 respectively. So that’s pixels for GD1 and points for GD2.

Well that’s it all you need to do is make an <img> tag with a src pointing to the script and it should load your image with your Feedburner count and message on it. :D

So that it. If you have any questions or problems leave a comment and I’ll get back to you ASAIC.

This tutorial was inspired by a tutorial on Marcofolio.net. It is in most parts the same however I have modified it to work with .ttf font files and added the shadow effect. It is not intended to offend anyone, it is however intended to expand slightly on an already excellent tutorial. :)

Add, Edit, Delete & Sorting Table Version 2 - TIAMOT

Posted 1 month, 1 week ago at 8:19 pm. 61 comments

Yes that’s right. It’s finally here version 2 of the script that seems to have gotten exceptionally popular.

Well actually it’s version 2.1 as I noticed an error just a few minutes ago but nevermind. ;) I have improved a lot of stuff in the code. It is now neater than ever and exceptionally easy to use all you need to do is configure a few things and you’re off.

I hope you like it. There are instructions in the zip file and you can read this read me underneath the download at the bottom of this post.

I’d also like to say a huge thanks to everyone who commented on the last version. You all helped me a lot by making me think of new features and easier ways to implement different parts of the script.

I am still providing support for the old version of the script so don’t worry, but I highly recommend you download this version if you were having problems running or using the older version. Again though any problems just leave a comment and I’ll get back to you as soon as I can.

Oh and I have had a few questions about donations so, here we go. I provide all help and scripts for free, however it takes a lot of my time & server costs so any donations would be welcome of any amount although they are not required.

Oh and the poll I had up before asking about the donation cloud. For those who said ‘what’s that?’ a donation cloud is a cloud of links, like a tag cloud that will automatically link to your site after you donate. The more you donate the bigger the link you get. Please vote on my new poll though, I think it would be interesting to see which OS you use the most. ;)

By the way the name does actually stand for something and as it says in the readme is a play on the mythical dragon Tiamat’s name. It stands for: The Integrated AJAX and MYSQL Ordering Table.

The demo is back up and can be accessed as before through the coding examples link at the top of the page or here

You can view the video tutorial for… Sorry the video tutorial is not available at the moment.

Download: TIAMOT - Add, Edit, Remove and Sort Version 2  TIAMOT - Add, Edit, Remove and Sort Version 2 (30.6 KB, 0 hits)

Click here to read TIAMOT’s Readme file.