root/dev/common/portrait.php @ 72

Revision 72, 2.0 KB (checked in by exi, 14 years ago)

Changed portrait to only store 128x128.
class.http.php now returns false on no connect.
Changed siggen, added errorpicture, changed output to jpg, enabled possibility to use several signatures, added 2 signatures as more examples

Line 
1<?php
2require_once("db.php");
3
4$id = intval($_GET['id']);
5$size = intval($_GET['size']);
6
7$portrait = "cache/portraits/".$id."_".$size.".jpg";
8if (file_exists($portrait))
9{
10    header("Content-Type: image/jpeg");
11    readfile($portrait);
12    exit;
13}
14
15// check for a valid, known external id
16$qry = new DBQuery();
17$qry->execute("select plt_externalid from kb3_pilots where plt_externalid = ".$id." limit 1");
18$row = $qry->getRow();
19if (!$id = $row['plt_externalid'])
20{
21    $portrait = "cache/portraits/0_".$size.".jpg";
22    if (file_exists($portrait))
23    {
24        header("Content-Type: image/jpeg");
25        readfile($portrait);
26        exit;
27    }
28}
29
30if (file_exists("cache/portraits/".$id."_128.jpg"))
31{
32    $img = imagecreatefromjpeg("cache/portraits/".$id."_128.jpg");
33}
34else
35{
36    $file = @file_get_contents("http://img.eve.is/serv.asp?s=128&c=".$id);
37    if ($img = imagecreatefromstring($file))
38    {
39        $fp = fopen("cache/portraits/".$id."_128.jpg", "w");
40        fwrite($fp, $file);
41        fclose($fp);
42    }
43    else
44    {
45        // try alternative access via fsockopen
46        // happens if allow_url_fopen wrapper is false
47        require_once("class.http.php");
48
49        $url = "http://img.eve.is/serv.asp?s=128&c=".$id;
50        $http = new http_request($url);
51        $file = $http->get_content();
52
53        if ($img = imagecreatefromstring($file))
54        {
55            $fp = fopen("cache/portraits/".$id."_128.jpg", "w");
56            fwrite($fp, $file);
57        }
58    }
59}
60
61if ($img)
62{
63    $newimg = imagecreatetruecolor($size, $size);
64    imagecopyresampled($newimg, $img, 0, 0, 0, 0, $size, $size, 128, 128);
65    imagejpeg($newimg, $portrait);
66    header("Content-Type: image/jpeg");
67    readfile($portrait);
68    exit;
69}
70
71// last try, we could not get a valid picture from the server
72// so output a red '!'
73$portrait = "img/portrait_0_".$size.".jpg";
74if (file_exists($portrait))
75{
76    header("Content-Type: image/jpeg");
77    readfile($portrait);
78    exit;
79}
80?>
Note: See TracBrowser for help on using the browser.