-
Notifications
You must be signed in to change notification settings - Fork 6
/
proofimg.php
109 lines (88 loc) · 4.49 KB
/
proofimg.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
<?php
/*
// +--------------------------------------------------------------------------+
// | Project: NVTracker - NetVision BitTorrent Tracker |
// +--------------------------------------------------------------------------+
// | This file is part of NVTracker. NVTracker is based on BTSource, |
// | originally by RedBeard of TorrentBits, extensively modified by |
// | Gartenzwerg. |
// | |
// | NVTracker is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | NVTracker is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with NVTracker; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +--------------------------------------------------------------------------+
// | Obige Zeilen dürfen nicht entfernt werden! Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/
function putChar($char, $index)
{
global $codeimage;
/* Verfügbare Schriften */
$fonts = Array("Hang_the_DJ.ttf", "comic.ttf", /*"dc_s.ttf",*/ "dauphinn.ttf");
/* Schriftart festlegen */
$usedfont = "proof/fonts/" . $fonts[rand(0, count($fonts)-1)];
/* Schriftgröße festlegen */
$size = rand(18, 36);
/* Schrift-Winkel festlegen */
$angle = rand(-45, 45);
/* Bounding Box ermitteln */
$sizeinfo = imagettfbbox($size, $angle, $usedfont, $char);
/* Rechteckkoordinaten des Boundary-Polygons ermitteln */
$minx = min($sizeinfo[0], $sizeinfo[2], $sizeinfo[4], $sizeinfo[6]);
$miny = min($sizeinfo[1], $sizeinfo[3], $sizeinfo[5], $sizeinfo[7]);
$maxx = max($sizeinfo[0], $sizeinfo[2], $sizeinfo[4], $sizeinfo[6]);
$maxy = max($sizeinfo[1], $sizeinfo[3], $sizeinfo[5], $sizeinfo[7]);
/* Ausmaße des Rechtecks berechnen */
$textwidth = $maxx - $minx;
$textheight = $maxy - $miny;
/* Textposition festlegen, damit der Text innerhalb der Bildgrenzen erscheint */
$textleft = rand(-$minx, 50-$textwidth-$minx) + ($index*50);
$texttop = rand(-$miny, 80-$textheight-$miny);
/* Text darstellen */
imagettftext($codeimage, $size, $angle, $textleft, $texttop, $textcolor, $usedfont, $char);
}
session_start();
$prooftext = $_SESSION["proofcode"];
/* Zufallsgenerator initialisieren */
srand(microtime()*360000);
/* Bild erstellen und Textfarbe (Schwarz) alloziieren */
$codeimage = imagecreatetruecolor(300, 80);
$textcolor = imagecolorallocate($codeimage, 0, 0, 0);
/* Hintergrund laden und einkopieren */
$bkg = imagecreatefrompng("proof/bkg/" . rand(1, 14) . ".png");
imagecopy($codeimage, $bkg, 0, 0, 0, 0, 300, 80);
imagedestroy($bkg);
/* 0-3 Artefakte (Störungen) */
$artifactcnt = rand(0,3);
/* Artefakte laden und einkopieren */
for($I=0; $I<$artifactcnt; $I++) {
$artifact = imagecreatefrompng("proof/artifacts/" . rand(1, 15) . ".png");
imagecopy($codeimage, $artifact, rand(0, 300-imagesx($artifact)), rand(0, 80-imagesy($artifact)), 0, 0, imagesx($artifact), imagesy($artifact));
imagedestroy($artifact);
}
/* 6-20 Linien */
$linecnt = rand(6, 20);
/* Linien zufällig zeichnen */
for($I=0; $I<$linecnt; $I++) {
$linecolor = imagecolorallocate($codeimage, rand(0, 128), rand(0, 128), rand(0, 128));
imageline($codeimage, rand(0, 300), rand(0, 80), rand(0, 300), rand(0, 80), $linecolor);
}
for ($I=0;$I<6;$I++) {
putChar($prooftext[$I], $I);
}
/* Bild ausgeben */
header("Content-Type: image/jpeg");
imagejpeg($codeimage, "",50);
/* Bild zerstören */
imagedestroy($codeimage);
?>