Skip to content
This repository was archived by the owner on Feb 5, 2022. It is now read-only.

Commit a60c49a

Browse files
committed
Initial commit
0 parents  commit a60c49a

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed

README

Whitespace-only changes.

email.php

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<title>Email address to png</title>
6+
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
7+
<style type="text/css">
8+
#main {
9+
text-align: center;
10+
}
11+
form {
12+
width: 27em;
13+
margin-left: auto;
14+
margin-right: auto;
15+
text-align: left;
16+
}
17+
label {
18+
display: inline-block;
19+
text-align: right;
20+
font-weight: bold;
21+
width: 9em;
22+
margin-left: 0px;
23+
margin-right: 1em;
24+
}
25+
input {
26+
display: inline-block;
27+
width: 15em;
28+
margin-right: 1em;
29+
}
30+
input.num {
31+
width: 3em;
32+
margin-right: 1em;
33+
text-align: right;
34+
}
35+
input#bt {
36+
width: 3em;
37+
margin-right: 1em;
38+
}
39+
.buttons {
40+
text-align: center;
41+
}
42+
#submitbutton{
43+
text-align: center;
44+
width: 5em;
45+
margin-left: auto;
46+
margin-right: auto;
47+
}
48+
</style>
49+
</head>
50+
<body>
51+
<div id="main">
52+
<h1>Email address to png</h1>
53+
<form action="email2.php" method="get" accept-charset="utf-8">
54+
<fieldset>
55+
<label for="addr">Email address</label><input type="text" id="addr" name="addr" /><br />
56+
</fieldset>
57+
<fieldset>
58+
<legend>Text configuration</legend>
59+
<label for="r">Color (R)</label><input type="text" class="num" id="r" name="r" value="0" />(0-255)<br />
60+
<label for="g">Color (G)</label><input type="text" class="num" id="g" name="g" value="0" />(0-255)<br />
61+
<label for="b">Color (B)</label><input type="text" class="num" id="b" name="b" value="0" />(0-255)<br />
62+
<!--<label for="a">Color (alpha)</label><input type="text" class="num" id="a" name="a" value="0" />(0-127)<br />-->
63+
</fieldset>
64+
<fieldset>
65+
<legend>Background configuration</legend>
66+
<label for="br">Color (R)</label><input type="text" class="num" id="br" name="br" value="255" />(0-255)<br />
67+
<label for="bg">Color (G)</label><input type="text" class="num" id="bg" name="bg" value="255" />(0-255)<br />
68+
<label for="bb">Color (B)</label><input type="text" class="num" id="bb" name="bb" value="255" />(0-255)<br />
69+
<label for="ba">Color (alpha)</label><input type="text" class="num" id="ba" name="ba" value="0" />(0-127)<br />
70+
</fieldset>
71+
<div class="buttons">
72+
<input type="submit" id="submitbutton" name="submitbutton" value="Submit" />
73+
</div>
74+
</form>
75+
<hr/>
76+
<p>
77+
참고: 변환되는 이미지에는 네이버 나눔고딕 폰트가 사용됩니다.
78+
</p>
79+
</div>
80+
</body>
81+
</html>

email2.php

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
if (!isset($_GET['addr'])) {
3+
echo 'Invalid input';
4+
exit;
5+
}
6+
$text = trim($_GET['addr']);
7+
$max_length = 254;
8+
if (strlen($text) > $max_length) {
9+
echo 'Too long address';
10+
exit;
11+
}
12+
13+
// font
14+
putenv('GDFONTPATH=' . realpath('./font/'));
15+
$font = 'NanumGothic';
16+
$fontsize = 10;
17+
$baseline = 11;
18+
$below_baseline = 4;
19+
$ysize = $baseline + $below_baseline;
20+
21+
// bounding box
22+
$bbox = imagettfbbox($fontsize, 0, $font, $text);
23+
$min_x = min(array($bbox[0], $bbox[2], $bbox[4], $bbox[6]));
24+
$max_x = max(array($bbox[0], $bbox[2], $bbox[4], $bbox[6]));
25+
//$min_y = min(array($bbox[1], $bbox[3], $bbox[5], $bbox[7]));
26+
//$max_y = max(array($bbox[1], $bbox[3], $bbox[5], $bbox[7]));
27+
28+
// image size
29+
$xmargin = 2;
30+
$ymargin = 2;
31+
$width = ($max_x - $min_x) + 2 * $xmargin;
32+
$height = $ysize + 2 * $ymargin;
33+
34+
// image create
35+
$pic = @imagecreatetruecolor($width, $height)
36+
or die("gg");
37+
imagesavealpha($pic, true); // !!!
38+
39+
// predefined colors
40+
$black = imagecolorallocate($pic, 0, 0, 0);
41+
$white = imagecolorallocate($pic, 255, 255, 255);
42+
43+
// text color
44+
if (isset($_GET['r']) && isset($_GET['g']) && isset($_GET['b'])) {
45+
$tmp_r = intval($_GET['r']);
46+
$tmp_g = intval($_GET['g']);
47+
$tmp_b = intval($_GET['b']);
48+
if (isset($_GET['a'])) {
49+
$tmp_a = intval($_GET['a']);
50+
} else {
51+
$tmp_a = 0;
52+
}
53+
if ((0 <= $tmp_r && $tmp_r <= 255)
54+
&& (0 <= $tmp_g && $tmp_g <= 255)
55+
&& (0 <= $tmp_b && $tmp_b <= 255)
56+
&& (0 <= $tmp_a && $tmp_a <= 127)) {
57+
$textcolor = imagecolorallocatealpha($pic, $tmp_r, $tmp_g, $tmp_b, $tmp_a);
58+
} else {
59+
echo 'Wrong text color';
60+
exit;
61+
}
62+
} else {
63+
$textcolor = $black;
64+
}
65+
66+
// background color
67+
if (isset($_GET['br']) && isset($_GET['bg']) && isset($_GET['bb'])) {
68+
$tmp_r = intval($_GET['br']);
69+
$tmp_g = intval($_GET['bg']);
70+
$tmp_b = intval($_GET['bb']);
71+
if (isset($_GET['ba'])) {
72+
$tmp_a = intval($_GET['ba']);
73+
} else {
74+
$tmp_a = 0;
75+
}
76+
if ((0 <= $tmp_r && $tmp_r <= 255)
77+
&& (0 <= $tmp_g && $tmp_g <= 255)
78+
&& (0 <= $tmp_b && $tmp_b <= 255)
79+
&& (0 <= $tmp_a && $tmp_a <= 127)) {
80+
$bgcolor = imagecolorallocatealpha($pic, $tmp_r, $tmp_g, $tmp_b, $tmp_a);
81+
} else {
82+
echo 'Wrong background color';
83+
exit;
84+
}
85+
} else {
86+
$bgcolor = $white;
87+
}
88+
89+
// background
90+
imagealphablending($pic, false); // !!!
91+
imagefilledrectangle($pic, 0, 0, $width, $height, $bgcolor);
92+
imagealphablending($pic, true); // !!!
93+
94+
// text
95+
$yoffset = $baseline + $ymargin;
96+
imagettftext($pic, $fontsize, 0, $xmargin, $yoffset, $textcolor, $font, $text);
97+
98+
// output
99+
header("Content-Type: image/png");
100+
//header("Content-Disposition: attachment; filename=\"mail.png\"");
101+
header("Content-Disposition: inline; filename=\"mail.png\"");
102+
imagepng($pic);
103+
imagedestroy($pic);
104+
?>

0 commit comments

Comments
 (0)