Twitter is the latest and greatest craze in social networking sites. As such, many developers and businesses are using it as a marketing technique. Today weíre going to come up with a method for creating a dynamic signature image for forum posts and emails that will automatically load your Twitter feed and display your latest Twitter status. Weíll be using PHP to grab the content along with GD2 support to create the image.
Iím going to be presenting the code in this article in an object-oriented fashion using PHP 5. If youíre not already using object-oriented programming techniques itís important that you begin doing that. You will be able to take advantage of more advanced features in PHP while building more robust applications. In my opinion, itís one of the subtle differences between a true programmer and a simple scripter.
The first step in creating this project was determining what size to make the final image. I considered the standard IAB ad unit sizes for banners, but they were either too big or too small for our purposes. The 60 pixel height on a full banner (also called impact banner) was perfect, but a width of 480 pixels takes up a bit more real estate than I would like for a low profile signature image. The half banner cuts that width in half, but then doesnít allow much room for both a userís avatar and text.
So I decided to shy away from a standard ad unit and compromise between the two, settling on a width of 380 pixels and a height of 60 pixels. With this size a userís avatar fits nicely inside the height and still allows about 300 pixels in width for the addition of text. With the capacity to house four lines, this fits the Twitter statusí character length specification pretty nicely, as you can see in the live example below.
Once I decided on a unit size for the image, I needed to build a background image that was the proper size. This is a simple background that will provide a nice- looking backdrop for the image as opposed to having it over a single background color. You can use Gimp or any other image creation software to create your own, or download the one I created in Photoshop here.