tagwall

Gesponsorde koppelingen

PHP script bestanden

  1. tagwall

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
error_reporting(E_ALL);

define('CURRENT_WALL', './walloftoday.jpg');
define('CLEAN_WALL', './muur.jpg');
define('FONT_DIRECTORY', './fonts/');
define('QUALITY', 85);

function
getRandomFont($font_directory){
    $fonts = array();
    $font_of_today = false;
    
    if($dir_handle = opendir($font_directory)){
        while (false !== ($font = readdir())) {
            $extention = end(explode('.', $font));
            if(strToLower($extention) == 'ttf'){
                $fonts[] = $font;
            }
        }
    }

    
    if(count($fonts) > 0){
        $font_of_today = $font_directory.$fonts[rand(0, count($fonts)-1)];
    }

    
    return $font_of_today;
}

function
buildAWall(){
    $wall = false;
    
    if(file_exists(CURRENT_WALL)){
        $wall = imagecreatefromjpeg(CURRENT_WALL);
    }
else{
        $wall = imagecreatefromjpeg(CLEAN_WALL);
    }

    
    return $wall;
}

function
printTag($wall, $text){
    if(!empty($text) && $wall && $style = getRandomFont(FONT_DIRECTORY)){
        list($width, $height) = getimagesize(CLEAN_WALL);
        $paint = imagecolorallocate($wall, rand(0,255), rand(0,255), rand(0,255));
        $drunkness = rand(-90, 90);
        $greatness = rand(15, 35);

        /* dankje Legolas */
        list($llx, $lly, $lrx, $lry, $urx, $ury, $ulx, $uly) = imagettfbbox($greatness, $drunkness, $style, $_GET['text']);
        $mostfarx = max(array($llx, $lrx, $urx, $ulx));
        $mostfary = max(array($lly, $lry, $ury, $uly));
        $mostnearx = min(array($llx, $lrx, $urx, $ulx));
        $mostneary = min(array($lly, $lry, $ury, $uly));

        $minx = 0;
        $miny = 0;

        if ($mostnearx < 0) {
            $minx += abs($mostnearx);
        }


        if ($mostneary < 0) {
            $miny += abs($mostneary);
        }


        $maxx = $width - $mostfarx;
        $maxy = $height - $mostfary;

        $left = rand($minx, $maxx);
        $top = rand($miny, $maxy);
    
        /* omdat je altijd wel foutjes tegenkomt */
        header('X-Font-Type:'.$style);
        header('X-X-coordinate:'.$top);
        header('X-Y-coordinate:'.$left);
        header('X-Font-Size:'.$greatness);
        header('X-Font_Angle:'.$drunkness);
        imagettftext($wall, $greatness, $drunkness, $left, $top, $paint, $style, $_GET['text']);
        imagejpeg($wall, CURRENT_WALL, QUALITY);
        imagedestroy($wall);
        return true;
    }
else{
        if(empty($text)){
            trigger_error('printTag: $text (2e parameter) is lees', E_USER_ERROR);
        }

        elseif(!$wall){
            trigger_error('printTag: $wall (1e parameter) is niet geldig', E_USER_ERROR);
        }

        elseif(!$style){
            trigger_error('printTag: kon geen goede $style krijgen via getRandomFont()', E_USER_ERROR);
        }

        return false;
    }
}


if(isset($_GET['text'])){
    if(printTag(buildAWall(), $_GET['text'])){
        echo 'Je hebt succesvol mijn muur beklad';
    }
else{
        echo 'Jong, mijn muur is dicht voor renovatie';
    }
}

/* optioneel: leegt iedere dag de muur, en hernoemt hem naar de tijd
if(filectime(CURRENT_WALL) < strtotime('-1 day')){
    rename(CURRENT_WALL, time().'.jpg');
    copy(CLEAN_WALL, CURRENT_WALL);
}
*/


?>

<form action="" method="get">
<input type="text" name="text"/>
<input type="submit"/>
</form>
<img src="<?php echo CURRENT_WALL; ?>" alt="tagwall" />

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.