Many days ago I built two image signature as my forum signature. One of the signatures 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
[/php]
2. Now we will get the time distance from now and the twitted time and will format it
[php]
$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”;
}
[/php]
3. So now we got our formatted twitter text
[php]
$status = “Tareq: $status ($date)”;
[/php]
4. Now it’s time to create our image
[php]
//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 );
[/php]
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]
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 );
[/php]
Hope you enjoyed the post đ
thanks, i relay need it. but the problem is i can’t use bangla status. it i use bangla status some higibiji đ font print. plz solved it.
http://devbd.co.cc/twitter.php
Thats the problem we face. PHP’s GD library has not full support for complex script like bangla. Although we can see bangla in image by setting bangla font, but it’s not clear and broken with the ‘āĻ-āĻāĻžāĻ°’, āĻ-āĻāĻžāĻ°’, ‘āĻ¯ā§āĻā§āĻ¤āĻžāĻā§āĻˇāĻ°’. I am looking for this solution also
Yeah! really! fine post!
But i am going to leave twitter.
I love Google Buzz! very much. đ
āĻāĻžāĻ āĻāĻŽāĻžāĻ° āĻā§ā§āĻ āĻ¸āĻžāĻāĻ āĻ āĻŋāĻāĻžāĻ¨āĻžāĻāĻž āĻāĻāĻā§ āĻāĻĄāĻŋāĻ āĻāĻ°ā§ āĻĻā§āĻ¨
.cc.co āĻšāĻŦā§
Great script, thanks for posting.
But how do I include the blue Twitter ‘t’ in the image?
I haven’t shown it here. I described the simple way. If you need to use the image, you need a blank png/jpg/gif image, and then there is a function to create from that image. Like imagecreatefrompng() creates any image from a given png image.
Was checking my inbound links.
talk.cmyweb.net
is not available now. Now blogging onshiplu.mokadd.im