Create your own twitter image signature
Many days ago i built two image signature as my forum signature. One of the signature shows the latest post from my blog and another shows my latest twitter update. I was inspired to do that signature by seeing Shiplu Vai’s signature. Originally he was using them and i copied the concept
Anyway, here is my latest blog post signature and here is my twitter signature
I will show you the process to create your own twitter image signature like me.
1. At first we will get the latest twitter update by this
<?php $username = "tareq_cse"; //Twitter Username $url = "http://twitter.com/statuses/user_timeline/$username.json?count=1"; //json request url $json = json_decode(file_get_contents($url)); $status = $json[0]->text; //get the status from array/object
2. Now we will get the time distance from now and the twitted time and will format it
$tweeted = strtotime($json[0]->created_at); //get the time as timestamp
$diff = time() - $tweeted; //get the time difference
//Get the time distance
if($diff > 86400)
{
$diff = round($diff/(60*60*24));
if($diff > 1) $date = "$diff days ago";
else $date = "$diff day ago";
}
else if($diff > 3599)
{
$diff = round($diff/3600);
if($diff > 1) $date = "$diff hours ago";
else $date = "$diff hour ago";
}
else
{
$diff = round($diff /60);
if($diff > 1) $date = "$diff minutes ago";
else $date = "$diff minute ago";
}
3. So now we got our formatted twitter text
$status = "Tareq: $status ($date)";
4. Now it’s time to create our image
header("Content-type: image/png");
$image = imagecreate(700, 16); //creating a demo image
$background = imagecolorallocate($image, 255, 255, 255); // defining the background of demo image
$textcolor = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));//random text color
imagestring($image, 3, 16, 1, $status, $textcolor); //creating the final image
imagepng($image);
imagedestroy($image);
We are done
Now run the page and you will get the latest twitter status as a image signature.
So here is the full code
<?php
$username = "tareq_cse"; //Twitter Username
$url = "http://twitter.com/statuses/user_timeline/$username.json?count=1"; //json request url
$json = json_decode(file_get_contents($url));
$status = $json[0]->text; //get the status from array/object
$tweeted = strtotime($json[0]->created_at); //get the time as timestamp
$diff = time() - $tweeted; //get the time difference
//Get the time distance
if($diff > 86400)
{
$diff = round($diff/(60*60*24));
if($diff > 1) $date = "$diff days ago";
else $date = "$diff day ago";
}
else if($diff > 3599)
{
$diff = round($diff/3600);
if($diff > 1) $date = "$diff hours ago";
else $date = "$diff hour ago";
}
else
{
$diff = round($diff /60);
if($diff > 1) $date = "$diff minutes ago";
else $date = "$diff minute ago";
}
$status = "Tareq: $status ($date)";
//Now print as a image
header("Content-type: image/png");
$image = imagecreate(700, 16); //creating a demo image
$background = imagecolorallocate($image, 255, 255, 255); // defining the background of demo image
$textcolor = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));//random text color
imagestring($image, 3, 16, 1, $status, $textcolor); //creating the final image
imagepng($image);
imagedestroy($image);
?>
Hope you enjoyed the post
