Source of trunk/img.php at revision HEAD (05/07/2008 10:05:35, 1336 bytes, 68 lines, language: php) [download]:

1
<?php
2
3
/*
4
** Image Fetch and Cache
5
** for CodewiseBlog
6
**
7
** by William R. Fraser <wrf@codewise.org>
8
** Copyright (c) 2008 Codewise.org
9
*/
10
11
function default_icon()
12
{
13
    header("Content-Type: image/jpeg");
14
    readfile("default_icon.jpg");
15
    exit();
16
}
17
18
require("settings.php");
19
require("l1_mysql.php");
20
21
$db = new L1_MySQL(SQL_HOSTSQL_USERSQL_PASSSQL_DB);
22
23
$q $db->issue_query("SELECT photo FROM blogs WHERE blogid = ".$db->prepare_value($_GET['blogid']));
24
if ($db->num_rows[$q] == || ($img_url $db->fetch_var($q)) == "") {
25
    default_icon();
26
}
27
28
if (!file_exists("cache/" md5($img_url))) {
29
30
    $size 75
31
32
    $image = @imagecreatefromstring(file_get_contents($img_url));
33
    if (!$image) {
34
        default_icon();
35
    }
36
37
    $w imagesx($image);
38
    $h imagesy($image);
39
40
    if ($w <= $size && $h <= $size)
41
    {
42
        imagejpeg($imageFSPATH "/cache/" md5($img_url));
43
        header("Content-Type: image/jpeg");
44
        readfile(FSPATH "/cache/" md5($img_url));
45
        exit;
46
    }
47
48
    $scalefactor $size / (($w $h) ? $w $h);
49
50
    $new_w $w $scalefactor;
51
    $new_h $h $scalefactor;
52
53
    $thumb imagecreatetruecolor($new_w$new_h);
54
55
    imagecopyresampled($thumb$image0000$new_w$new_h$w$h);
56
57
    imagejpeg($thumbFSPATH "/cache/" md5($img_url));
58
59
}
60
61
header("Content-Type: image/jpeg");
62
63
readfile(FSPATH "/cache/" md5($img_url));
64
65
exit();
66
67
?>
68

powered by Codewise Manager v0.1-DEV :: 32.20ms, 6 ops, 3 queries