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: http://ansuz.nl/php_lib/bfheroes/tipoftheday.xml. 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: http://ansuz.nl/php_lib/bfheroes/tip.php?method=randomTip
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: http://ansuz.nl/bla/bfheroes/.
Generate your Quake Live signature here: http://ansuz.nl/toys/quakelive/
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!
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.
Works a lot better with HTML2PS/PDF than DOMpdf. The first can handle DIVs, where the latter can’t!
More on this later…
Using a template parser to create a page and sending the output to dompdf work great too! It’s only a matter of following the instructions on their website to set it up.
The only problem that I ran into had something to do with my own template parser.
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. 😉
An image can be added for use with pdf in two ways:
- Let dompdf determine the size for the image acoording to the DOMPDF_DPI setting in dompdf_config.inc.php or
- 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:
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:
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.
Warning: Illegal string offset 'language' in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510
Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513
The default fonts that come with pdf aren’t enough for me, so I want to install a new font. To do so you need to have ttf2pt1 installed on the webserver. Unfortunately that’s not the case for me. The dompdf manual says the following about having problems installing fonts:
Also, if you have problems installing the font files, you can try and use the distributed dompdf_font_family_cache.dist file in lib/fonts. Copy this file to lib/fonts/dompdf_font_family_cache and edit it directly to match the files present in your lib/fonts directory.
Let’s see if this will work…
EDIT: Ok, found a nice .afm font (serpentine), put it in the lib/fonts dir of dompdf 0.5.1 and edited the dompdf_font_family_cache file, the following has been added:
'normal' => DOMPDF_FONT_DIR . 'SerpeMed',
'bold' => DOMPDF_FONT_DIR . 'SerpeBol',
'italic' => DOMPDF_FONT_DIR . 'SerpeMedObl',
'bold_italic' => DOMPDF_FONT_DIR . 'SerpeBolObl',
When I try to make a pdf using this font with dompdf an error is thrown and no pdf is generated…
To be continued…
Edit: An .atm AND .pfa or .pfb file are required to make it work. So now it works great! 🙂
In order to make nice pdf documents from html pages I stumbled upon dompdf. This tool can actually read a html page and output it as a pdf file. The problem with the tool right now is that it doesn’t support ‘div’ positioning (yet), so you have to “layout” everything with tables.
The first test is making a bit more complex table and have that outputted the right way. For now only the rowspan attribute doesn’t seem to work correctly.
empty($_POST) instead of an if containing
$_POST == "". This gave me a lot of trouble to find out why there wasn’t anything sent by my mailer, who can receive variables using both GET and POST. Oops! :S
This is valid obviously for any associative Array. 😉
– the empty() function documentation