Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Created August 12, 2013 12:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylemcdonald/6210591 to your computer and use it in GitHub Desktop.
Save kylemcdonald/6210591 to your computer and use it in GitHub Desktop.
Inbox Unread reports inbox statistics hourly in the form of a Twitter avatar.
<!--
Inbox Unread reports inbox statistics hourly in the form of a Twitter avatar.
To run Inbox Unread first copy this php script to your server. Put your background
avatar adjacent to this file as "input.jpeg". Mine is 548x548 and all the positions
are setup for that size. Next go to http://script.google.com/ and sign in. Click
"Create a script for GMail" and replace the template with this code:
function processInbox() {
var unreadCount = GmailApp.getInboxUnreadCount();
var totalCount = GmailApp.getInboxThreads().length;
var url = "http://yourserver.com/thisdirectory/" +
"?unreadCount=" + unreadCount +
"&totalCount=" + totalCount;
var response = UrlFetchApp.fetch(url);
};
(Make sure to replace the URL with your server and directory for this php script.)
Save the script. Hit the "Play" button to make sure it works. It will ask you
to give permissions to the app. Click the "Project Triggers" button, set it to
run once an hour, and hit "Save".
Next go to https://ifttt.com/ and sign in. Add a new recipe using the "Date and
Time" and "Twitter" channels. Set Date and Time to run every hour on the half
hour. For Twitter set it to "Update profile picture" and point the Photo URL
to the "avatar.jpeg" that is generated by this php script.
<3 Kyle McDonald (2013)
-->
<?php
function imagettftextoffset($im, $size, $angle, $x, $y, $offset, $text) {
$font = 'bebas.ttf'; # use a font that you like
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, $size, $angle, $x + $offset, $y + $offset, $black, $font, $text);
imagettftext($im, $size, $angle, $x + $offset, $y - $offset, $black, $font, $text);
imagettftext($im, $size, $angle, $x - $offset, $y + $offset, $black, $font, $text);
imagettftext($im, $size, $angle, $x - $offset, $y - $offset, $black, $font, $text);
imagettftext($im, $size, $angle, $x, $y, $white, $font, $text);
}
$x=35;
$y1=50;
$y2=320;
$size=210;
$offset=6;
$padding=15;
$smallsize=60;
$im = imagecreatefromjpeg("input.jpeg");
imagettftextoffset($im, $size, 0, $x + $padding + $smallsize, $y1 + $size, $offset, $_GET["unreadCount"]);
imagettftextoffset($im, $size, 0, $x + $padding + $smallsize, $y2 + $size, $offset, $_GET["totalCount"]);
imagettftextoffset($im, $smallsize, 90, $x + $smallsize, $y1 + $size, $offset, "UNREAD");
imagettftextoffset($im, $smallsize, 90, $x + $smallsize, $y2 + $size, $offset, "INBOX");
imagejpeg($im, "avatar.jpeg", 85);
imagedestroy($im);
?>
<img src="avatar.jpeg"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment