-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
88 lines (74 loc) · 1.92 KB
/
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
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
<?php
require __DIR__.'/vendor/autoload.php';
use GDText\Box;
use GDText\Color;
$url = parse_url($_SERVER['REQUEST_URI']);
preg_match('/\/(\d+)(x(\d+))?(\.(\w+))?/', $url['path'], $match);
$width = !empty($match[1]) ? $match[1] : 500;
$height = !empty($match[3]) ? $match[3] : $width;
$width = min($width, 3000);
$height = min($height, 3000);
$format = isset($match[5]) ? $match[5] : 'png';
$font_size = min([$height / 8.5,$width / 8.5]);
$slogans = [
'Obey',
'Obey and Conform',
'Marry and Reproduce',
'Watch T.V.',
'Stay Asleep',
'No Thought',
'Submit',
'Conform',
'This is your God',
'No Independent Thought',
'Buy',
'Do Not Think',
'Do Not Question Authority',
'Work 8 Hours',
'Play 8 Hours',
'Sleep 8 Hours',
'Stay Asleep'
];
$random_slogan = $slogans[mt_rand(0, count($slogans) - 1)];
if (isset($_SERVER['QUERY_STRING'])) {
parse_str($_SERVER['QUERY_STRING'], $queries);
$text = strtoupper(
array_key_exists('text', $queries) ?
$queries['text'] :
$random_slogan
);
} else {
$text = strtoupper($random_slogan);
}
$im = imagecreatetruecolor($width, $height);
$backgroundColor = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $backgroundColor);
$borderColor = imagecolorallocate($im, 225, 225, 225);
imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
$box = new Box($im);
$box->setFontFace(__DIR__.'/fonts/font.otf');
$box->setFontColor(new Color(0, 0, 0));
$box->setFontSize($font_size);
$box->setBox(20, 20, $width - 40, $height - 40);
$box->setTextAlign('center', 'center');
$box->setLineHeight(1);
$box->draw($text);
switch ($format) {
case 'gif':
header('Content-type: image/gif');
imagegif($im);
break;
case 'jpg':
case 'jpeg':
header('Content-type: image/jpeg');
imagejpeg($im);
break;
case 'png':
header('Content-type: image/png');
imagepng($im);
break;
default:
die('Unsupported File Format. Use png, jpeg or gif.');
break;
}
?>