Magl: Check-in [01982ff718]

Very simple and tiny libravatar server

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Initial import
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA3-256:01982ff718a50512e9136946b4405c87a2f7ca0f8f5142905fe9bbe9058182d8
User & Date: milouse 2018-10-15 22:22:44
Context
2018-10-15
22:22
Initial import Leaf check-in: 01982ff718 user: milouse tags: trunk
22:21
initial empty check-in check-in: ff9b910375 user: milouse tags: trunk
Changes

Added index.php.

























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
 * Very simple libravatar server
 *
 * This implementation requires the following:
 * - gd
 * - DNS correctly setup (see https://wiki.libravatar.org/api/ )
 * - pngs saved in the pub folder and named with the following commands:
 *   echo -n email | md5sum
 *   echo -n email | sha256sum
 */


function display_png($file) {
  header('Content-type: image/png');
  readfile($file);
  exit;
}

function resize_image($filename, $size) {
  list($width, $height) = getimagesize($filename);
  $src = imagecreatefrompng($filename);
  $dst = imagecreatetruecolor($size, $size);
  imagecopyresampled($dst, $src, 0, 0, 0, 0, $size, $size, $width, $height);
  $filename_sized = $filename . '_' . $size;
  imagepng($dst, $filename_sized);
  imagedestroy($dst);
  display_png($filename_sized);
}

if (empty($_GET['avatar'])) {
  display_png('./pub/default');
}
$filename = './pub/' . $_GET['avatar'];

$size = 80;
if (!empty($_GET['s']) && $_GET['s'] > 0 && $_GET['s'] <= 512) {
  $size = $_GET['s'];
}

if (!file_exists($filename)) {
  if (!empty($_GET['d'])) {
    $loc = $_GET['d'];
    $gravatar_default = array('identicon', 'monsterid', 'mm', 'wavatar', 'retro');
    if (in_array($loc, $gravatar_default)) {
      $loc = 'https://gravatar.com/avatar/' . $filename . '?d=' . $loc . '&s=' . $size;
    }
    header('Location: ' . $loc);
    exit;
  }
  resize_image('./pub/default', $size);
}

$filename_sized = $filename . '_' . $size;
if (file_exists($filename_sized)) {
  display_png($filename_sized);
}

resize_image($filename, $size);
?>