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.