From Twitter REST API v1.1, APP can update user’s Profile Background Image. The details of the API is here. First of all download tmhOAuth from github. To update background we will need oauth_token, oauth_token_secret. Here is an example to get those https://github.com/themattharris/tmhOAuth-examples/blob/master/auth.php
The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. So here is the code
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => $twitter_app_settings.key,
'consumer_secret' => $twitter_app_settings.secret,
'user_token' => $oauth_token,
'user_secret' => $oauth_token_secret,
));
$imgbinary = file_get_contents($file_link);
$img_str = base64_encode($imgbinary);
$params = array(
'image' => "@{$file_link};type={$file_type]};filename={$file_name}",
);
$params['use'] = 'true';
$code = $tmhOAuth->request('POST', $tmhOAuth->url("1.1/account/update_profile_background_image.json"),
$params,
true, // use auth
true // multipart
);
if ($code == 200)
echo 'background image updated.';
else
echo 'Something went worng!!';