walk-of-fame
Code (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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
error_reporting(E_ALL);
ini_set('display-errors', 1);
class KEK
{
public static $size = 40; // grootte van font
public static $font = 'fonts/verdana.ttf'; // font
public static $saveFile = 'kek.jpg'; // bestand om in op te slaan
public static $originalFile = 'images/phphulp_gd.jpg'; // originele afbeelding
public static $y = 365; // verticale positie van tekst
public $walk_of_fame = null; // image resource
public $name = null; // naam die op afbeelding wordt gezet
public $color = null; // kleur van font
public $location = null; // locatie van nieuw bestand
public function __construct() {
if (!$this->walk_of_fame = $this->makeResource()) {
throw new Exception('Fout tijdens het maken van een resource');
}
if (!$this->color = $this->getColor()) {
throw new Exception('Fout tijdens het bepalen van de kleur');
}
}
private function makeResource() {
$resource = imagecreatefromjpeg(self::$originalFile);
return $resource;
}
public function setColor($color) {
$this->color = $color;
}
private function processName($name) {
if (strlen($name) > 15) {
$name = substr($name, 0, 15);
}
return strtoupper($name);
}
private function getColor() {
return imagecolorallocate($this->walk_of_fame, 251, 238, 210);
}
private function getX() {
$text_info = imageTTFBbox(self::$size, 0, self::$font, $this->name);
$mid_text = abs(($text_info[2] - $text_info[0]) / 2);
$mid_image = imagesx($this->walk_of_fame) / 2;
$x = $mid_image - $mid_text;
return $x;
}
private function getY() {
return self::$y;
}
public function kekIt($name) {
$this->name = $this->processName($name);
if (!imagettftext($this->walk_of_fame, self::$size, 0, $this->getX(), $this->getY(), $this->color, self::$font, $this->name)) {
throw new Exception('Fout tijdens het plaatsen van tekst op de afbeelding');
}
if (!imagejpeg($this->walk_of_fame, self::$saveFile)) {
throw new Exception('Fout tijdens het aanmaken van de nieuwe afbeelding');
}
@imagedestroy($this->walk_of_fame);
return self::$saveFile;
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['naam'])) {
$naam = $_POST['naam'];
}
else {
$naam = "kek";
}
try {
$kek = new KEK();
$walk_of_fame = $kek->kekIt($naam);
}
catch (Exception $e) {
die('<h1>' . $e->getMessage() . '</h1>');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Walk Of Fame</title>
<link rel="stylesheet" type="text/css" media="screen" href="css.css" />
</head>
<body>
<div id="container">
<div id="content">
<div id="top">
<p>Kom ook op de <em>Hollywood Walk Of Fame</em><p>
<p>Vul je naam, zodat je ook een gepast plaastje krijgt tussen de <em>PHPhulp</em>ers</p>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="formulier" method="post">
<fieldset>
<legend> <em>Walk Of Fame</em> </legend>
<ol>
<li><label for="naam">Naam:</label> <input type="text" id="naam" name="naam" value=""/></li>
</ol>
<div id="line"> </div>
<ol>
<input type="submit" id="submit" name="submit" value="Versturen" />
</ol>
</fieldset>
</form>
<img src="<?php echo $walk_of_fame; ?>" alt="<?php echo $naam; ?>" />
</div>
</div>
</body>
</html>
error_reporting(E_ALL);
ini_set('display-errors', 1);
class KEK
{
public static $size = 40; // grootte van font
public static $font = 'fonts/verdana.ttf'; // font
public static $saveFile = 'kek.jpg'; // bestand om in op te slaan
public static $originalFile = 'images/phphulp_gd.jpg'; // originele afbeelding
public static $y = 365; // verticale positie van tekst
public $walk_of_fame = null; // image resource
public $name = null; // naam die op afbeelding wordt gezet
public $color = null; // kleur van font
public $location = null; // locatie van nieuw bestand
public function __construct() {
if (!$this->walk_of_fame = $this->makeResource()) {
throw new Exception('Fout tijdens het maken van een resource');
}
if (!$this->color = $this->getColor()) {
throw new Exception('Fout tijdens het bepalen van de kleur');
}
}
private function makeResource() {
$resource = imagecreatefromjpeg(self::$originalFile);
return $resource;
}
public function setColor($color) {
$this->color = $color;
}
private function processName($name) {
if (strlen($name) > 15) {
$name = substr($name, 0, 15);
}
return strtoupper($name);
}
private function getColor() {
return imagecolorallocate($this->walk_of_fame, 251, 238, 210);
}
private function getX() {
$text_info = imageTTFBbox(self::$size, 0, self::$font, $this->name);
$mid_text = abs(($text_info[2] - $text_info[0]) / 2);
$mid_image = imagesx($this->walk_of_fame) / 2;
$x = $mid_image - $mid_text;
return $x;
}
private function getY() {
return self::$y;
}
public function kekIt($name) {
$this->name = $this->processName($name);
if (!imagettftext($this->walk_of_fame, self::$size, 0, $this->getX(), $this->getY(), $this->color, self::$font, $this->name)) {
throw new Exception('Fout tijdens het plaatsen van tekst op de afbeelding');
}
if (!imagejpeg($this->walk_of_fame, self::$saveFile)) {
throw new Exception('Fout tijdens het aanmaken van de nieuwe afbeelding');
}
@imagedestroy($this->walk_of_fame);
return self::$saveFile;
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['naam'])) {
$naam = $_POST['naam'];
}
else {
$naam = "kek";
}
try {
$kek = new KEK();
$walk_of_fame = $kek->kekIt($naam);
}
catch (Exception $e) {
die('<h1>' . $e->getMessage() . '</h1>');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Walk Of Fame</title>
<link rel="stylesheet" type="text/css" media="screen" href="css.css" />
</head>
<body>
<div id="container">
<div id="content">
<div id="top">
<p>Kom ook op de <em>Hollywood Walk Of Fame</em><p>
<p>Vul je naam, zodat je ook een gepast plaastje krijgt tussen de <em>PHPhulp</em>ers</p>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="formulier" method="post">
<fieldset>
<legend> <em>Walk Of Fame</em> </legend>
<ol>
<li><label for="naam">Naam:</label> <input type="text" id="naam" name="naam" value=""/></li>
</ol>
<div id="line"> </div>
<ol>
<input type="submit" id="submit" name="submit" value="Versturen" />
</ol>
</fieldset>
</form>
<img src="<?php echo $walk_of_fame; ?>" alt="<?php echo $naam; ?>" />
</div>
</div>
</body>
</html>
De CSS die op de website staat.
Code (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
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
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
/* CSS Document */
html, body {
font-family: Verdana, Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
height: 100%;
text-align:center;
}
#container {
background: #e2f7ba url(images/bg_wof.gif) center top repeat-y;
width: 850px;
text-align:left;
margin: 0 auto;
padding: 0;
}
#content {
margin: 0px 6px;
}
#center {
margin: 0px auto;
width:400px;
}
#top {
margin: 0;
padding: 5px;
font-size: 14px;
text-align:center;
}
img {
margin: 10px 0 0 1px;
//margin-top: -10px;
height: 715px;
}
/*formulier*/
form.formulier {
width: 100%;
font-size: 13px;
color: #333;
padding: 0;
}
form.formulier legend {
padding: 0 2px 0 0;
color: #333;
font-weight: bold;
}
form.formulier fieldset label {
width: 200px;
display: inline-block;
line-height: 1.8;
vertical-align: top;
color: #333;
}
form.formulier fieldset {
border: none;
border-top: 1px solid #C9DCA6;
border-bottom: 1px solid #C9DCA6;
margin-top: 10px;
margin: 3px 0 0;
background: none;
}
form.formulier fieldset ol {
margin: 0;
padding: 0;
display: inline-block;
}
form.formulier div#line {
margin: 0;
padding: 0;
width: 50%;
background: url(images/line_div.gif) left top repeat-x;
}
form.formulier fieldset li {
padding: 5px 10px 7px;
list-style: none;
padding: 5px;
margin: 0;
}
form.formulier fieldset legend {
padding: 0 0 5px;
font-weight: normal;
}
form.formulier fieldset label {
width: auto;
}
form.formulier input#naam {
background: #C9DCA6;
}
form.formulier input#submit {
margin-top: -10px;
margin-bottom: -5px;
//margin-bottom: 5px;
//margin-left: 6px;
}
div#container em {
font-weight: bold;
font-style: normal;
}
html, body {
font-family: Verdana, Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
height: 100%;
text-align:center;
}
#container {
background: #e2f7ba url(images/bg_wof.gif) center top repeat-y;
width: 850px;
text-align:left;
margin: 0 auto;
padding: 0;
}
#content {
margin: 0px 6px;
}
#center {
margin: 0px auto;
width:400px;
}
#top {
margin: 0;
padding: 5px;
font-size: 14px;
text-align:center;
}
img {
margin: 10px 0 0 1px;
//margin-top: -10px;
height: 715px;
}
/*formulier*/
form.formulier {
width: 100%;
font-size: 13px;
color: #333;
padding: 0;
}
form.formulier legend {
padding: 0 2px 0 0;
color: #333;
font-weight: bold;
}
form.formulier fieldset label {
width: 200px;
display: inline-block;
line-height: 1.8;
vertical-align: top;
color: #333;
}
form.formulier fieldset {
border: none;
border-top: 1px solid #C9DCA6;
border-bottom: 1px solid #C9DCA6;
margin-top: 10px;
margin: 3px 0 0;
background: none;
}
form.formulier fieldset ol {
margin: 0;
padding: 0;
display: inline-block;
}
form.formulier div#line {
margin: 0;
padding: 0;
width: 50%;
background: url(images/line_div.gif) left top repeat-x;
}
form.formulier fieldset li {
padding: 5px 10px 7px;
list-style: none;
padding: 5px;
margin: 0;
}
form.formulier fieldset legend {
padding: 0 0 5px;
font-weight: normal;
}
form.formulier fieldset label {
width: auto;
}
form.formulier input#naam {
background: #C9DCA6;
}
form.formulier input#submit {
margin-top: -10px;
margin-bottom: -5px;
//margin-bottom: 5px;
//margin-left: 6px;
}
div#container em {
font-weight: bold;
font-style: normal;
}