This repository has been archived by the owner on Mar 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.php
66 lines (54 loc) · 1.71 KB
/
render.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
<?php
if(isset($_GET['d'])) header('Content-type: image/jpeg');
$_GET['t'] = str_replace("-", "%20", str_replace("--", "%0A", $_GET['t']));
$renderImg = imagecreatefromjpeg('img/render.jpg');
$renderFont = dirname(__FILE__) . '/big_noodle_titling_oblique.ttf';
$renderColor = imagecolorallocate($renderImg, 250, 202, 6);
$textLines = explode("\n", urldecode($_GET['t']));
foreach($textLines as $no => $textLine)
{
printline:
if($no > 1) break;
$typeSpace = imagettfbbox(250, 0, $renderFont, $textLine);
$textWidth = abs($typeSpace[4] - $typeSpace[0]) + 10;
if($textWidth > 3450)
{
$wordsLine = explode(" ", $textLine);
$saved = 0;
$i = count($wordsLine)-1;
while($saved < $textWidth-3450)
{
$wordTypeSpace = imagettfbbox(250, 0, $renderFont, $wordsLine[$i]);
$wordWidth = abs($wordTypeSpace[4] - $wordTypeSpace[0]) + 10;
$saved += $wordWidth;
$i--;
}
list($textLine, $addNextLine) = array_chunk($wordsLine, $i+1);
$lineSpace = 3508-$textWidth+$saved+250;
}
elseif(isset($saved))
{
$lineSpace = 3508-$textWidth-$saved;
}
else
{
$lineSpace = 3508-$textWidth;
}
imagettftext($renderImg, 250, 0, $lineSpace/2, 750+$no*400, $renderColor, $renderFont, (is_array($textLine) ? implode(" ", $textLine) : $textLine));
if(count($textLines) == 1 && !$no)
{
$no = 1; $textLine = implode(" ", $addNextLine);
unset($addNextLine);
unset($saved);
goto printline;
}
}
if(!isset($_GET['d'])) ob_start();
imagejpeg($renderImg);
imagedestroy($renderImg);
if(!isset($_GET['d'])) {
$imgData = ob_get_contents();
ob_get_clean();
echo base64_encode($imgData);
}
?>