Skip to content

Instantly share code, notes, and snippets.

@AJenbo
Forked from openp2pdesign/GourceGravatarExample.py
Last active October 14, 2021 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AJenbo/544aaf50bf691975d6d38b72e0a6ab21 to your computer and use it in GitHub Desktop.
Save AJenbo/544aaf50bf691975d6d38b72e0a6ab21 to your computer and use it in GitHub Desktop.
Download git contributor avatars from GitHub and Gravatar for use with Gource
<?php
// Place in any subfolder of your project, run `php DownloadAvatarsForGource.php`
$list = shell_exec('git shortlog -sne');
if (!$list) {
return;
}
$lines = explode("\n", $list);
$context = stream_context_create(["http" => ["header" => "User-agent: DownloadAvatarsForGource"]]);
foreach ($lines as $line) {
$line = trim($line, " 0123456789>");
$line = explode('<', $line);
$line = array_filter($line);
$user = array_values($line);
$user[0] = trim($user[0]);
if (!empty($user[1])) {
$dataUrl = 'https://api.github.com/search/users?utf8=%E2%9C%93&q='.$user[1].'+in%3Aemail&type=Users';
$data = @file_get_contents($dataUrl, false, $context);
if ($data !== false) {
$data = json_decode($data, true);
if (!empty($data['items'][0]['avatar_url'])) {
$image = @file_get_contents($data['items'][0]['avatar_url'], false, $context);
if ($image != false) {
file_put_contents($user[0].'.png', $image);
continue;
}
}
}
}
$image = @file_get_contents('https://github.com/'.$user[0].'.png', false, $context);
if ($image != false) {
file_put_contents($user[0].'.png', $image);
continue;
}
if ($user[1]) {
$image = @file_get_contents('http://www.gravatar.com/avatar/'.md5($user[1])."?d=identicon&s=256", false, $context);
if ($image != false) {
file_put_contents($user[0].'.png', $image);
continue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment