1. Computing & Technology

Discuss in my forum

Dynamic PHP Banner with your Latest Twitter Post

By , About.com Guide

3 of 3

Create the Image
 //Here we set the font. The file arial.tff is in the home directory. Change accordingly. 

$font = 'arial.ttf';

//This is where we set our background image

$handle = imagecreatefrompng("bgimage.png") ;

//Background Color

$bg_color = ImageColorAllocate ($handle, 135, 206, 250);

//Text Color

$txt_color = ImageColorAllocate ($handle, 0, 0, 0);

//This adds @YourName to the banner

imagettftext($handle, 20, 0, 100, 25, $txt_color, $font, "@$name");

//And this adds your status

imagettftext($handle, 8, 0, 105, 45, $txt_color, $font, $status1);

ImagePng ($handle);

?>

Here we adding in all the components to make the image. First we are choosing our font. In our case we chose Arial. Our arial.tff file is in our home directory, but you can change this to point to wherever your font is uploaded on your site. We then define the background image. If you wanted a plain color background instead of an image you could replace that line with this one:

 $handle = ImageCreate (468, 60) or die ("Cannot Create image"); 

The next two lines are the background color and the text color. Again, you can change these to alter the look of your banner. Finally we print your twitter name and status on the banner or signature file.

Save this file as whatever you want. We'll call ours banner.php. You then call the file just as you would an image, for example:

 <img src="http://www.yoursite.com/banner.php"> 

Download Code Here

  1. About.com
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Create a Dynamic Twitter Signature with PHP - Latest Post as a Twitter Banner with PHP

©2012 About.com. All rights reserved.

A part of The New York Times Company.