<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Load a new font</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.imageline.html">imageline</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.imagepalettecopy.html">imagepalettecopy</a></div> <div class="up"><a href="ref.image.html">GD and Image Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.imageloadfont" class="refentry"> <div class="refnamediv"> <h1 class="refname">imageloadfont</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">imageloadfont</span> — <span class="dc-title">Load a new font</span></p> </div> <div class="refsect1 description" id="refsect1-function.imageloadfont-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>imageloadfont</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$file</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>imageloadfont()</strong></span> loads a user-defined bitmap and returns its identifier. </p> </div> <div class="refsect1 parameters" id="refsect1-function.imageloadfont-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">file</code></em></span> <dd> <p class="para"> The font file format is currently binary and architecture dependent. This means you should generate the font files on the same type of CPU as the machine you are running PHP on. </p> <p class="para"> <table class="doctable table"> <caption><strong>Font file format</strong></caption> <thead> <tr> <th>byte position</th> <th>C data type</th> <th>description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>byte 0-3</td> <td>int</td> <td>number of characters in the font</td> </tr> <tr> <td>byte 4-7</td> <td>int</td> <td> value of first character in the font (often 32 for space) </td> </tr> <tr> <td>byte 8-11</td> <td>int</td> <td>pixel width of each character</td> </tr> <tr> <td>byte 12-15</td> <td>int</td> <td>pixel height of each character</td> </tr> <tr> <td>byte 16-</td> <td>char</td> <td> array with character data, one byte per pixel in each character, for a total of (nchars*width*height) bytes. </td> </tr> </tbody> </table> </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.imageloadfont-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The font identifier which is always bigger than 5 to avoid conflicts with built-in fonts or <strong><code>FALSE</code></strong> on errors. </p> </div> <div class="refsect1 examples" id="refsect1-function.imageloadfont-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3260"> <p><strong>Example #1 <span class="function"><strong>imageloadfont()</strong></span> usage example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Create a new image instance<br /></span><span style="color: #0000BB">$im </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">50</span><span style="color: #007700">, </span><span style="color: #0000BB">20</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$black </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$white </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Make the background white<br /></span><span style="color: #0000BB">imagefilledrectangle</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">49</span><span style="color: #007700">, </span><span style="color: #0000BB">19</span><span style="color: #007700">, </span><span style="color: #0000BB">$white</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Load the gd font and write 'Hello'<br /></span><span style="color: #0000BB">$font </span><span style="color: #007700">= </span><span style="color: #0000BB">imageloadfont</span><span style="color: #007700">(</span><span style="color: #DD0000">'./04b.gdf'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagestring</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">$font</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #DD0000">'Hello'</span><span style="color: #007700">, </span><span style="color: #0000BB">$black</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Output to browser<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-type: image/png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.imageloadfont-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.imagefontwidth.html" class="function" rel="rdfs-seeAlso">imagefontwidth()</a> - Get font width</span></li> <li class="member"> <span class="function"><a href="function.imagefontheight.html" class="function" rel="rdfs-seeAlso">imagefontheight()</a> - Get font height</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.imageline.html">imageline</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.imagepalettecopy.html">imagepalettecopy</a></div> <div class="up"><a href="ref.image.html">GD and Image Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>