ch03s02.html
42.6 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Necessary system requirements for the library</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch03.html" title="Chapter 3. The Long Version: Installing the Library"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Necessary system requirements for the library</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 3. The Long Version: Installing the Library</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Necessary system requirements for the library"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec.sys-req"></a>Necessary system requirements for the library</h2></div></div></div>
<p>In order to run the JpGraph library there are some prerequisites that must be
fulfilled. The PHP installation must have the low level graphic primitive library
"GD" enabled and if TTF fonts shall work in the graphs the FreeType 2.x library must
be enabled and installed in the PHP setup. Most modern PHP systems (since at least
2006) usually have these extensions enabled and installed by default which means it
is usually rather simple to get the library working. </p>
<p>However, there are many systems out there and some older non-standard systems will
require some manual intervention to work correctly.</p>
<div class="caution" title="Caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3>
<p>One more time; The library is not guaranteed to run on a 64Bit OS. We will
point out this several more time during this manual.</p>
</div>
<div class="sect2" title="Verifying the PHP/GD installation"><div class="titlepage"><div><div><h3 class="title"><a name="sec.verifying-phpgd-inst"></a>Verifying the PHP/GD installation</h3></div></div></div>
<p>The first and most important step is to make sure that your PHP installations
has the GD library enabled. The easiest way to find out if this has been enabled
or not is to create a one line PHP program that has only one instruction,
<code class="code">phpinfo()</code></p>
<p>
</p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code"> </span><span class="hl-identifier">phpinfo</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-inlinetags">?></span></pre></td></tr></table></div><p>
</p>
<p>Store this basic program as <code class="filename">phpinfo.php</code> in the document
root. Then point the browser to</p>
<p>
<code class="filename">http://localhost/phpinfo.php</code>
</p>
<p>If the steps above was followed the browser should now show a lot of
information about the PHP installation. In order to find out if the GD have been
installed and enabled look for the GD section in the output. The figure below
shows a typical output of this section</p>
<div class="figure"><a name="fig.phpinfo-gd"></a><p class="title"><b>Figure 3.2. phphinfo() GD-Information</b></p><div class="figure-contents">
<div class="mediaobject"><img src="images/phpinfo-gd.png" alt="phphinfo() GD-Information"></div>
</div></div><p><br class="figure-break">There are three important points to notice here. </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
<p>The GD Version. It should be 2.0.x. The GD version has been
shipped with PHP for the last four years so this should not really
be a problem. If for some odd reason the system only have GD 1.x
installed then JpGraph 2.x, and 3.x cannot be used but it is still
possible to use JpGraph 1.x.</p>
<p>In addition the "bundled" version of GD should be used. This
version is maintained together with PHP and is usually much more up
to date then the stand alone GD version.</p>
</li><li class="listitem">
<p>FreeType version. This is required in order to use TTF fonts. This
should be at least version 2.3.x Previous versions of the FreeType
library have had known issues which has caused issues when used
together with JpGraph.</p>
</li><li class="listitem">
<p>The final point worth checking is what type of image encoding the
installation supports. The most common formats are PNG and JPEG. By
default the library uses the PNG encoding format so it is important
to check that the line that says "PNG Support" has "enabled" as
value. As a rule of thumb PNG usually gives the smallest sizes of
graph (best compression) so this is the recommended format. The only
exception to this rule might be if a photo is used as background in
the graph. Then it is possible that JPEG encoding gives a better
compression since this is a destructive format (while PNG is a
lossless format).</p>
<p>For legacy reason it is also possible to use GIF encoding if the
server supports this but if PNG is installed there are no good
technical reasons to use GIF compression format. (The only possible
usage of GIF is the ability to create an animated image by
concatenating a number of GIF images which are then displayed in
sequence. This is not possible with the (old) PNG standard.)</p>
</li></ol></div>
<p>In order to remove any remaining doubts that the installation works as
intended the following PHP script that only uses the GD library primitives
should be run. This allows troubleshooting the installation without involving
the additional complexity of JpGraph to make sure that the basics are in
place.</p>
<p>Store the script in <a class="xref" href="ch03s02.html#example.checkgd" title="Example 3.1. Verifying the GD installations (checkgd.php)">Example 3.1. Verifying the GD installations (<code class="filename">checkgd.php</code>) </a> your document root as
<code class="filename">"checkgd.php"</code></p>
<div class="example"><a name="example.checkgd"></a><p class="title"><b>Example 3.1. Verifying the GD installations (<code class="filename">checkgd.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content="text/plain; charset=utf-8"</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$im</span><span class="hl-code"> = @</span><span class="hl-identifier">imagecreate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-number">200</span><span class="hl-code">, </span><span class="hl-number">100</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">or</span><span class="hl-code"> </span><span class="hl-reserved">die</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">"</span><span class="hl-string">cannot create a new gd image.</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$background_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">240</span><span class="hl-code">, </span><span class="hl-number">240</span><span class="hl-code">, </span><span class="hl-number">240</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$border_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">50</span><span class="hl-code">, </span><span class="hl-number">50</span><span class="hl-code">, </span><span class="hl-number">50</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$text_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">233</span><span class="hl-code">, </span><span class="hl-number">14</span><span class="hl-code">, </span><span class="hl-number">91</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagerectangle</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">199</span><span class="hl-code">,</span><span class="hl-number">99</span><span class="hl-code">,</span><span class="hl-var">$border_color</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagestring</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">5</span><span class="hl-code">, </span><span class="hl-number">10</span><span class="hl-code">, </span><span class="hl-number">40</span><span class="hl-code">, </span><span class="hl-quotes">"</span><span class="hl-string">a simple text string</span><span class="hl-quotes">"</span><span class="hl-code">, </span><span class="hl-var">$text_color</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">header</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">content-type: image/png</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagepng</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><br class="example-break"> <div class="figure"><a name="fig.checkgd"></a><p class="title"><b>Figure 3.3. Verifying the GD installations <code class="uri"><a class="uri" href="example_src/checkgd.html" target="_top">(<code class="filename">checkgd.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/checkgd.png" alt="Verifying the GD installations (checkgd.php)"></span> </div></div><br class="figure-break">
<p>Now point the browser to this file and fetch the script. This should show an
image in the browser with the text "a simple text string" similar to what is
shown in <a class="xref" href="ch03s02.html#fig.checkgd" title="Figure 3.3. Verifying the GD installations (checkgd.php)">Figure 3.3. Verifying the GD installations <code class="uri"><a class="uri" href="example_src/checkgd.html" target="_top">(<code class="filename">checkgd.php</code>)</a></code> </a></p>
<p>In order to be really sure that the GD 2.x version of the GD library is
installed (as opposed to just GD 1.x) we need to use a slightly more advanced
script that makes use of some features available in GD 2.x but not in GD 1.x.
The largest difference is the support for TrueColor images in GD 2.x so we
create a script that makes use of a truecolor canvas..</p>
<div class="example"><a name="example.checkgd2"></a><p class="title"><b>Example 3.2. Verifying GD2 (<code class="filename">checkgd2.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content="text/plain; charset=utf-8"</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$im</span><span class="hl-code"> = </span><span class="hl-identifier">imagecreatetruecolor</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-number">300</span><span class="hl-code">, </span><span class="hl-number">200</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$black</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$lightgray</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">230</span><span class="hl-code">, </span><span class="hl-number">230</span><span class="hl-code">, </span><span class="hl-number">230</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$darkgreen</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">80</span><span class="hl-code">, </span><span class="hl-number">140</span><span class="hl-code">, </span><span class="hl-number">80</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$white</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagefilledrectangle</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">299</span><span class="hl-code">,</span><span class="hl-number">199</span><span class="hl-code"> ,</span><span class="hl-var">$lightgray</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagerectangle</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">299</span><span class="hl-code">,</span><span class="hl-number">199</span><span class="hl-code">,</span><span class="hl-var">$black</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagefilledellipse</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">,</span><span class="hl-number">150</span><span class="hl-code">,</span><span class="hl-number">100</span><span class="hl-code">,</span><span class="hl-number">210</span><span class="hl-code">,</span><span class="hl-number">110</span><span class="hl-code">,</span><span class="hl-var">$white</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagefilledellipse</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">,</span><span class="hl-number">150</span><span class="hl-code">,</span><span class="hl-number">100</span><span class="hl-code">,</span><span class="hl-number">200</span><span class="hl-code">,</span><span class="hl-number">100</span><span class="hl-code">,</span><span class="hl-var">$darkgreen</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">header</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">Content-type: image/png</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagepng</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><br class="example-break"> <div class="figure"><a name="fig.checkgd2"></a><p class="title"><b>Figure 3.4. Verifying GD2 <code class="uri"><a class="uri" href="example_src/checkgd2.html" target="_top">(<code class="filename">checkgd2.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/checkgd2.png" alt="Verifying GD2 (checkgd2.php)"></span> </div></div><br class="figure-break">
<p>In the same way as before store this file on the server and point the browser
to it. The result should be the same image as is shown in <a class="xref" href="ch03s02.html#fig.checkgd2" title="Figure 3.4. Verifying GD2 (checkgd2.php)">Figure 3.4. Verifying GD2 <code class="uri"><a class="uri" href="example_src/checkgd2.html" target="_top">(<code class="filename">checkgd2.php</code>)</a></code> </a></p>
<p><span class="bold"><strong>In order to use the library it is absolutely necessary that the
above two scrips works as described. If this is not the case the
<code class="filename">php.ini</code> file needs to be checked as described in
the next section. </strong></span></p>
</div>
<div class="sect2" title="Enabling GD library in php.ini for PH5"><div class="titlepage"><div><div><h3 class="title"><a name="id2476056"></a>Enabling GD library in php.ini for PH5</h3></div></div></div>
<p>If neither of the two example above worked and the GD section didn't exist in
the output from <code class="code">phpinfo()</code> the chances are that the GD library has
not been enabled in the <code class="filename">php.ini</code> file.</p>
<p>The first problem to solve is therefore to locate the
<code class="filename">php.ini</code> file in the installation. Depending on the type
of server (and OS) this can be in different places. If the system is running on
a Unix server the <code class="filename">php.ini</code> file is most likely stored in
either <code class="filename">/etc/php.ini</code> , <code class="filename">/etc/php/php.ini</code>
, <code class="filename">/etc/php5/php.ini</code> or
<code class="filename">/etc/php5/apache/php.ini</code>
</p>
<p>
</p><div class="tip" title="Tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Tip</h3>
<p>Check the output of <code class="code">phpinfo()</code> to find out what
<code class="filename">php.ini</code> file the installation is
reading.</p>
</div><p>
</p>
<p>On a windows server there is no standard location since it completely depends
on how the installation of the HTTP server and PHP was done. For example if the
WAMP server was installed and put in the top directory
<code class="filename">c:\wamp\</code> the <code class="filename">php.ini</code> file is
installed under <code class="filename">c:\wamp\bin\apache\apache2.2.11\bin\php.ini</code>
</p>
<p>Open <code class="filename">php.ini</code> in a editor and locate the line </p>
<p><code class="code">extension_dir = <some-path-here></code></p>
<p>The directory path specified above is the directory where all PHP extension
modules are stored. On a Unix system this is typically specified as
<code class="filename">/usr/lib/php5/extensions</code> now examine that directory and
check if an extension called "<code class="filename">gd.so</code>" (for Unix) or
"<code class="filename">gd.dll</code>" (for Windows) exists (and is un-commented). If
this extension cannot be found then this extension needs to be installed. For
example, many Unix/Linux installation requires that the extra modules in PHP is
manually enabled/installed through the appropriate Packet manager as the example
below shows.</p>
<p>
</p><div class="example"><a name="id2489639"></a><p class="title"><b>Example 3.3. Installing GD through RPM packet manager</b></p><div class="example-contents">
<p>
</p><pre class="screen">$/> sudo zypper install php5-gd</pre><p>
</p>
</div></div><p><br class="example-break">
</p>
</div>
<div class="sect2" title="Verifying TTF fonts"><div class="titlepage"><div><div><h3 class="title"><a name="id2489648"></a>Verifying TTF fonts</h3></div></div></div>
<p>This section is only intended to verify if that support exists for TTF fonts.
If this does not work or if it is already known that there are no support for
TTF fonts then please go directly to <a class="xref" href="ch03s04.html" title="Installing and configuring Font support">Installing and configuring Font support</a></p>
<p>In order to check if basic TTF font support is available create the following
script in the document root and name it <code class="filename">checkttf.php</code>
</p>
<p>Then it is necessary to locate on the system exactly where the TTF fonts are
stored and update the defines for the paths and/or the name of the TTF fonts
that is know to exist. </p>
<p>
</p><div class="example"><a name="example.checkttf"></a><p class="title"><b>Example 3.4. Verifying TTF with a known font (<code class="filename">checkttf.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment"> content="text/plain; charset=utf-8"</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> Change this defines to where Your fonts are stored</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">DEFINE</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">TTF_DIR</span><span class="hl-quotes">"</span><span class="hl-code">,</span><span class="hl-quotes">"</span><span class="hl-string">/usr/share/fonts/truetype/</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Change this define to a font file that You know that You have</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">DEFINE</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">TTF_FONTFILE</span><span class="hl-quotes">"</span><span class="hl-code">,</span><span class="hl-quotes">"</span><span class="hl-string">arial.ttf</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Text to display</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">DEFINE</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">TTF_TEXT</span><span class="hl-quotes">"</span><span class="hl-code">,</span><span class="hl-quotes">"</span><span class="hl-string">Hello World!</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$im</span><span class="hl-code"> = </span><span class="hl-identifier">imagecreatetruecolor</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-number">400</span><span class="hl-code">, </span><span class="hl-number">100</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$white</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$black</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$border_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">50</span><span class="hl-code">, </span><span class="hl-number">50</span><span class="hl-code">, </span><span class="hl-number">50</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagefilledrectangle</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">399</span><span class="hl-code">,</span><span class="hl-number">99</span><span class="hl-code">,</span><span class="hl-var">$white</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagerectangle</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">399</span><span class="hl-code">,</span><span class="hl-number">99</span><span class="hl-code">,</span><span class="hl-var">$border_color</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagettftext</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">30</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">90</span><span class="hl-code">, </span><span class="hl-number">60</span><span class="hl-code">, </span><span class="hl-var">$black</span><span class="hl-code">, </span><span class="hl-identifier">TTF_DIR</span><span class="hl-code">.</span><span class="hl-identifier">TTF_FONTFILE</span><span class="hl-code">,</span><span class="hl-identifier">TTF_TEXT</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">header</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">Content-type: image/png</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagepng</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.checkttf"></a><p class="title"><b>Figure 3.5. Verifying TTF with a known font <code class="uri"><a class="uri" href="example_src/checkttf.html" target="_top">(<code class="filename">checkttf.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/checkttf.png" alt="Verifying TTF with a known font (checkttf.php)"></span> </div></div><p><br class="figure-break">
</p>
<p>As usual point the browser to this script and fetch the image. If thing works
an image identical to what is shown in <a class="xref" href="ch03s02.html#fig.checkttf" title="Figure 3.5. Verifying TTF with a known font (checkttf.php)">Figure 3.5. Verifying TTF with a known font <code class="uri"><a class="uri" href="example_src/checkttf.html" target="_top">(<code class="filename">checkttf.php</code>)</a></code> </a> should be visible.</p>
<div class="sect3" title="Name of TTF font files"><div class="titlepage"><div><div><h4 class="title"><a name="sec3.name-of-ttf-files"></a>Name of TTF font files</h4></div></div></div>
<p>The library has built in support for large number of TTF fonts, this
includes both the standard MS WEB core fonts as well as Vera and DejaVu
fonts. In addition a number of non-latin fonts are supported. This includes
both Japanese, Chinese, Hebrew and Russian fonts. See <a class="xref" href="ch03s04.html#sec2.using-non-latin-fonts" title="Using non-latin based fonts with JpGraph">Using non-latin based fonts with JpGraph</a> and <a class="xref" href="ch08s08.html" title="Character encoding">Character encoding</a> for more on how to use non-latin
fonts and encodings.</p>
<p>In order for the fonts to be usable by the library the font files must
have the following names (these are the standard names)</p>
<p>More information on how to use TTF fonts in scripts can be found in <a class="xref" href="ch08.html" title="Chapter 8. Text and font handling">Chapter 8. <i>Text and font handling</i></a></p>
<p>
</p><div class="table"><a name="table.ttf-font-files"></a><p class="title"><b>Table 3.1. Latin TTF font file names</b></p><div class="table-contents">
<table summary="Latin TTF font file names" border="1"><colgroup><col class="c1"><col class="c2"><col class="newCol3"><col class="c3"><col class="c4"><col class="c5"></colgroup><thead><tr><th>Font family name</th><th>Symbolic name</th><th>Normal, <code class="code">FS_NORMAL</code></th><th>Bold, <code class="code">FS_BOLD</code></th><th>Italic, <code class="code">FS_ITALIC</code></th><th>Bold italic, <code class="code">FS_BOLDITALIC</code></th></tr></thead><tbody><tr><td>Courier</td><td>FF_COURIER</td><td><code class="filename">cour.ttf</code></td><td><code class="filename">courbd.ttf</code></td><td><code class="filename">couri.ttf</code></td><td><code class="filename">courbi.ttf</code></td></tr><tr><td>Georgia</td><td>FF_GEORGIA</td><td><code class="filename">georgia.ttf</code></td><td><code class="filename">georgiab.ttf</code></td><td><code class="filename">georgiai.ttf</code></td><td> </td></tr><tr><td>Trebuche</td><td>FF_TREBUCHE</td><td><code class="filename">trebuc.ttf</code></td><td><code class="filename">trebucbd.ttf</code></td><td><code class="filename">trebucit.ttf</code></td><td><code class="filename">trebucbi.ttf</code></td></tr><tr><td>Verdana</td><td>FF_VERDANA</td><td><code class="filename">verdana.ttf</code></td><td><code class="filename">verdanab.ttf</code></td><td><code class="filename">verdanai.ttf</code></td><td> </td></tr><tr><td>Times roman</td><td>FF_TIMES</td><td><code class="filename">times.ttf</code></td><td><code class="filename">timesbd.ttf</code></td><td><code class="filename">timesi.ttf</code></td><td><code class="filename">timesbi.ttf</code></td></tr><tr><td>Comic</td><td>FF_COMIC</td><td><code class="filename">comic.ttf</code></td><td><code class="filename">comicbd.ttf</code></td><td> </td><td> </td></tr><tr><td>Arial</td><td>FF_ARIAL</td><td><code class="filename">arial.ttf</code></td><td><code class="filename">arialbd.ttf</code></td><td><code class="filename">ariali.ttf</code></td><td><code class="filename">arialbi.ttf</code></td></tr><tr><td>Vera</td><td>FF_VERA</td><td><code class="filename">Vera.ttf</code></td><td><code class="filename">VeraBd.ttf</code></td><td><code class="filename">VeraIt.ttf</code></td><td><code class="filename">VeraBI.ttf</code></td></tr><tr><td>Vera mono</td><td>FF_VERAMONO</td><td><code class="filename">VeraMono.ttf</code></td><td><code class="filename">VeraMoBd.ttf</code></td><td><code class="filename">VeraMoIt.ttf</code></td><td><code class="filename">VeraMoBI.ttf</code></td></tr><tr><td>Vera serif</td><td>FF_VERASERIF</td><td><code class="filename">VeraSe.ttf</code></td><td><code class="filename">VeraSeBd.ttf</code></td><td> </td><td> </td></tr><tr><td>(Chinese) Simsun</td><td>FF_SIMSUN</td><td><code class="filename">simsun.ttc</code></td><td><code class="filename">simhei.ttf</code></td><td> </td><td> </td></tr><tr><td>Chinese</td><td>FF_CHINESE</td><td><code class="filename">bkai00mp.ttf</code></td><td> </td><td> </td><td> </td></tr><tr><td>(Japanese) Mincho</td><td>FF_MINCHO</td><td><code class="filename">ipamp.ttf</code></td><td> </td><td> </td><td> </td></tr><tr><td>(Japanese) P Mincho</td><td>FF_PMINCHO</td><td><code class="filename">ipamp.ttf</code></td><td> </td><td> </td><td> </td></tr><tr><td>(Japanese) Gothic</td><td>FF_GOTHIC</td><td><code class="filename">ipag.ttf</code></td><td> </td><td> </td><td> </td></tr><tr><td>(Japanese) P Gothic</td><td>FF_PGOTHIC</td><td><code class="filename">ipagp.ttf</code></td><td> </td><td> </td><td> </td></tr><tr><td>(Hebrew) David</td><td>FF_DAVID</td><td><code class="filename">DAVIDNEW.TTF</code></td><td> </td><td> </td><td> </td></tr><tr><td>(Hebrew) Miriam</td><td>FF_MIRIAM</td><td><code class="filename">MRIAMY.TTF</code></td><td> </td><td> </td><td> </td></tr><tr><td>(Hebrew) Ahron</td><td>FF_AHRON</td><td><code class="filename">ahronbd.ttf</code></td><td> </td><td> </td><td> </td></tr><tr><td>DejaVu Sans Serif</td><td>FF_DV_SANSSERIF</td><td><code class="filename">DejaVuSans.ttf</code></td><td><code class="filename">DejaVuSans-Bold.ttf</code>, </td><td><code class="filename">DejaVuSans-Oblique.ttf</code></td><td><code class="filename">DejaVuSans-BoldOblique.ttf</code></td></tr><tr><td>DejaVu Sans Serif Mono</td><td>FF_DV_SANSSERIFMONO</td><td><code class="filename">DejaVuSansMono.ttf</code></td><td><code class="filename">DejaVuSansMono-Bold.ttf</code></td><td><code class="filename">DejaVuSansMono-Oblique.ttf</code></td><td><code class="filename">DejaVuSansMono-BoldOblique.ttf</code></td></tr><tr><td>DejaVu Sans Serif Condensed</td><td>FF_DV_SANSSERIFCOND</td><td><code class="filename">DejaVuSansCondensed.ttf</code></td><td><code class="filename">DejaVuSansCondensed-Bold.ttf</code></td><td><code class="filename">DejaVuSansCondensed-Oblique.ttf</code></td><td><code class="filename">DejaVuSansCondensed-BoldOblique.ttf</code></td></tr><tr><td>DejaVu Serif</td><td>FF_DV_SERIF</td><td><code class="filename">DejaVuSerif.ttf</code></td><td><code class="filename">DejaVuSerif-Bold.ttf</code></td><td><code class="filename">DejaVuSerif-Italic.ttf</code></td><td><code class="filename">DejaVuSerif-BoldItalic.ttf</code></td></tr><tr><td>DejaVu Serif Condensed</td><td>FF_DV_SERIFCOND</td><td><code class="filename">DejaVuSerifCondensed.ttf</code></td><td><code class="filename">DejaVuSerifCondensed-Bold.ttf</code></td><td><code class="filename">DejaVuSerifCondensed-Italic.ttf</code></td><td><code class="filename">DejaVuSerifCondensed-BoldItalic.ttf</code></td></tr></tbody></table>
</div></div><p><br class="table-break">
</p>
<p>
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
<p>For the DejaVu fonts there are actually two common sets of name in
usage depending on how long it has been since the fonts where
installed. The library knows of both sets of names and will try them
in order selecting to use the first one available.</p>
</div><p>
</p>
</div>
</div>
<div class="sect2" title="Support for different image formats"><div class="titlepage"><div><div><h3 class="title"><a name="id2490624"></a>Support for different image formats</h3></div></div></div>
<p>By default the standard GD image library supports the PNG graphic format. </p>
<p>Hence by default only PNG is supported. If JPEG support is needed this might
require additional libraries that must be installed and enabled for usage by
PHP/GD (in the <code class="filename">php.ini </code>file), again please see PHP
documentation for specifics. For most practical purposes PNG is a better format
since it normally achieves better compression then GIF (typically by a factor of
2 for the types of images generated by JpGraph). </p>
<p>In comparison with JPEG format PNG is also better for the type of images
generated by this library. </p>
<p>So, the bottom line is that there should be very good reasons to choose any
other image encoding formats than PNG. By default the image format is set to
"auto". This means that JpGraph automatically chooses the best available image
encoding format using the preferred order "PNG", "GIF" and "JPG".</p>
<div class="note" title="No support for SVG" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">No support for SVG</h3>
<p>We have received may requests to add support for SVG image output.
Unfortunately we have investigated this and concluded that it is
(surprisingly!) not technically possible to do this. The main reason is that
with the current standard there is no way to statically determine the
bounding boxes for texts. This is further described in <a class="xref" href="apk.html" title="Appendix K. Why it is not possible to add a SVG backend to JpGraph">Appendix K. <i>Why it is not possible to add a SVG backend to JpGraph</i></a></p>
</div>
</div>
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>