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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php

/**

* PHP Default Font Image Pluggable Set 
*
* Copyright (C) 2006 Matsuda Shota
* http://sgssweb.com/
* admin@sgssweb.com
*
* ------------------------------------------------------------------------
*
*/



require_once 'package.fig.php';




class 
DefaultFontImagePluggableSet
    
extends GMIPluggableSet
{
    var 
$defaultVariables = array(
        
"text" => null,
        
"size" => null,
        
"font" => null,
        
"color" => "0x000000",
        
"alpha" => "100",
        
"leading" => "{size}",
        
"padding" => 0,
        
"width" => null,
        
"height" => null,
        
"align" => "left",
        
"valign" => "middle",
        
"bgcolor" => "0xffffff",
        
"bgtrans" => "true",
        
"blank" => false,
        
"bgimage" => null,
        
"antialias" => 4,
        
"type" => "gif",
        
"palette" => null,
        
"quality" => 100,
        
"file" => null
    
);
    
    function 
DefaultFontImagePluggableSet() {
        
parent::GMIPluggableSet();
    }
    
    function 
getExpression() {
        
        
$vars $this->getVariables();
        
        if (isset(
$vars['exec'])) {
            return 
$vars['exec'];
        }
        
        
// text drawing
        
if ($vars['text'] !== null && $vars['font'] !== null && $vars['size'] !== null) {
            
$font "font {font:{font},{size},{leading}};";
        
            if (
$vars['width'] !== null && $vars['height'] !== null) {
                
$string "string {text},0,0,{width},{height},{align},{valign};";
                
$autoResize "autoresize width;";
            }
            else if (
$vars['width'] !== null) {
                
$string "string {text},0,0,{width},{align};";
                
$autoResize "autoresize both;";
            }
            else {
                
$string "string {text},0,0,{align};";
                
$autoResize "autoresize both;";
            }
        }
        else {
            
$font "";
            
$string "";
        }
        
        
// background image drawing
        
if ($vars['bgimage'] !== null) {
            
$pattern "pattern {image:{bgimage}};";
        }
        else {
            
$pattern "";
        }
        
        
// foreground color
        
if (preg_match('/^\s*\{\s*\w+\:.*\}\s*$/'$vars['color'])) {
            
$foreground "color {color};";
        }
        else {
            
$foreground "color {color:{color},{alpha}};";
        }
        
        
// background color
        
if (preg_match('/^\s*\{\s*\w+\:.*\}\s*$/'$vars['bgcolor'])) {
            
$background "color {bgcolor};";
        }
        else {
            
$background "color {color:{bgcolor}};";
        }
        
        
// image type selection
        
switch ($vars['type']) {
            case 
"jpeg":
                
$type "type {type},{quality};";
                break;
        
        
            case 
"png":
                if (
$vars['palette'] === null) {
                    
$type "type {type};";
                    
                    if (
$vars['blank']) {
                        
$type .= "$background blank;";
                    }
                }
                else {
                    if (
$vars['bgtrans'] == 'false') {
                        
$type "type {type},{palette};";
                    }
                    else {
                        
$type "type {type},{palette},{color:{bgcolor}};";
                    }
                }
                break;
            
            case 
"gif":
            default:
                if (
$vars['palette'] === null) {
                    
$vars['palette'] = 255;
                }
                if (
$vars['bgtrans'] == 'false') {
                    
$type "type {type},{palette};";
                }
                else {
                    
$type "type {type},{palette},{color:{bgcolor}};";
                }
        }
        
        
// file output
        
if ($vars['file'] !== null) {
            
$file "file {file};";
        }
        else {
            
$file "";
        }

        return 
"size {width},{height}; $autoResize $type $file padding {padding}; $background fill; $pattern $foreground antialias {antialias}; $font $string";
    }
    
    function 
getVariables() {
        return 
array_merge($this->defaultVariables$_GET);
    }
}



// remove slashes inserted by "magic quotes"
if (get_magic_quotes_gpc()) {
    
$_GET array_map("strip_text_slashes"$_GET);
    
$_POST array_map("strip_text_slashes"$_POST);
    
$_COOKIE array_map("strip_text_slashes"$_COOKIE);
}
function 
strip_text_slashes($arg) {
    if(!
is_array($arg)) {
        
$arg stripslashes($arg);
    }
    else if (
is_array($arg)) {
        
$arg array_map("strip_text_slashes"$arg);
    }
    return 
$arg;
}



$pluggableSet = new DefaultFontImagePluggableSet();

$fig = new FontImageGenerator();
$fig->setPluggableSet($pluggableSet);
$fig->execute();


?>