-
Notifications
You must be signed in to change notification settings - Fork 32
/
b64img.php
50 lines (37 loc) · 1.28 KB
/
b64img.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
<?php
/*
displays base64_decode($_GET['text']); - useful for email addresses
example usage:
<img src="email.php?r=255&g=0&b=0&text=cHVyZW1hbmdvLmNvLnVrQGdtYWlsLmNvbQ==">
*/
header("Content-Type: image/png");
// get amounts and titles from session.
$text = base64_decode($_GET['text']);
// calculate required width and height of image
$pic_width = strlen($text)*6;
$pic_height = 12;
// create image
$pic = ImageCreate($pic_width+1,$pic_height+1);
// allocate colours
$white = ImageColorAllocate($pic,255,255,255);
$grey = ImageColorAllocate($pic,200,200,200);
$lt_grey = ImageColorAllocate($pic,210,210,210);
$black = ImageColorAllocate($pic,0,0,0);
$trans_temp = ImageColorAllocate($pic,254,254,254);
$transparent = ImageColorTransparent($pic,$trans_temp);
// using isset not !empty, as values could=0, therefore "empty"
if(isset($_GET['r']) && isset($_GET['g']) && isset($_GET['b']))
{
$user = ImageColorAllocate($pic,intval($_GET['r']),intval($_GET['g']),intval($_GET['b']));
} else {
$user = $black;
}
// transparent fill for background
ImageFilledRectangle($pic,0,0,$pic_width,$pic_height,$trans_temp);
// draw text
ImageString($pic,2,0,0,$text,$user);
// output image
ImagePNG($pic);
// remove image from memory
ImageDestroy($pic);
?>