|
| 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