BF:H Random tip

Whenever you join a BatlleField: Heroes server a ‘Tip of the day’ is displayed. I was wondering where I could find all the tips and if anybody had already done something with them (i.e. create a service to get a random tip).

I couldn’t find anything after a Google search, so I started looking around. It turns out that all in game copy is stored in a file called ‘strings.csv‘. If you have BF:Heroes installed in the default location, you can find it here: ‘C:\Program Files\EA Games\Battlefield Heroes\mods\bfheroes\Localization‘. This file is a comma separated values file which you can open with Notepad and even Excel.

The bits I needed to have tips displayed are the rows starting with ‘WEST_FE_Loading_tip_ingress_‘ and ‘WEST_FE_Loading_tip_text_‘. What I’ve done for now is copy those fields over into an XML file: I guess a next step could be a little script (or AIR application) that takes the ‘scripts.csv‘ file and converts it to XML in the format I need.

I then created a small PHP script to load the XML file and display a random quote, see here:
The first line is the ‘tip header’, the second the ‘tip body’. Both are wrapped in a ‘span’-tag with a unique class name so you can style it the way you want.

The final bit I did is loading a random tip on a site with my BF:H stats and applying some styling to it:

Quake Live Signature Generator

Generate your Quake Live signature here:

So why did I build it?
I love playing video games and I love Quake Live (QL). So I was a little disappointed to find out that there was no signature generator available yet for Quake Live. After a bit of ‘Googling’ I found a post on how to show your stats on mIRC. The example used a socket connection to retrieve QL profile page and using good ol’ web scraping technologies to retrieve all relevant data.

I started building this in Flex using a socket connection to load the QL profile. I then managed to retrieve all relevant date and store it in a usable way. When I uploaded the app, I found out you need a special cross domain policy file for socket connections on your server. Also, this socket cross domain policy needs to be served from port 843. As my hosting provider doesn’t give me control to that level I had to find something else. Quite obviously a URLLoader did the trick. It’s funny how you can get quite mislead by an example you find somewhere else.

After that I realised that most forums don’t allow you to use Flash in your signatures and if they do, they usually limit it to something like 15KB. My signature is nowhere near 15K.

I decided to finally take the smart approach and use PHP to retrieve the QL profile and generate an XML file with all relevant data. After that I started messing around with the GD Lib to create a PNG version of the signature. The script that creates the image first loads the XML and then creates the signature, you can see the result of that above. As you can see this image is quite large, so I’m planning to create a medium and a small version in the near future.

All in all getting data from point A, modifying it at point B and using it at C is a lot of fun!


imagettftext resulting in blurry text

It’s been a while since I used PHP and I’m finally doing something with it again. I’m working on creating dynamic forum signatures and of course need to use some text in that. I’m using the imagettftext() method to create my text using the Arial font. I was getting strange blurred result and reading the documentation suggested I should turn the anti-aliassing off. It turn out that the GDLib JPG compression is pretty bad and caused all the blurring. When I switched to PNG all blurryness was gone.

Solution: Make sure you use PNG, not JPEG.

Cannot modify header information

This is one of the weirdest errors I ran into. The full error:

Warning: Cannot modify header information – headers already sent by (output started at /home/mysite/public_html/some.php:23) in /home/mysite/public_html/someother.php on line 69

In most cases the solution to this is removing any leading and trailing spaces of your php open and close tags in the some.php file. In other words, remove all spaces before your < ?php tag and after your ?> tag

A simple but very strange solution…

Note: remove the space between the ‘<' and '?php', this is merely done so it gets displayed on this page. 😉

dompdf experiment pt3 – images

An image can be added for use with pdf in two ways:

  1. Let dompdf determine the size for the image acoording to the DOMPDF_DPI setting in or
  2. Determine the size in CSS using a unit other than pixels

Method 1: place your image in your html doc and change the line following line to your preferred DPI setting:

define(“DOMPDF_DPI”, “300”);

Note: This gives you little control over the width/height of the image used in your pdf. (Keeping in mind that you might want to do this dynamically and let users upload their own images)

Method 2: set the image size in your CSS, ie:

img.fixedsize {
width: 150mm;

This gives the image (with class name ‘fixedsize’) a fixed width of 150mm. Very usefull to stay ‘true’ to a certain layout.
Note: The disadvantage of this method is that an image can be too small to decently use in your predefined size and thus appears grainy in your pdf file.

All in all this works fine and I ran into no trouble at all.