php-doc-en/reference/image/functions/imageftbbox.xml
Nikola Smolenski d732584196 - New entities for GD image library
- Capitalize Content-Type in all affected files as in RFC 2616 (and IMO prettier)


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@309972 c90b9560-bf6c-de11-be94-00142212c4b1
2011-04-05 15:03:52 +00:00

229 lines
6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id='function.imageftbbox' xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>imageftbbox</refname>
<refpurpose>Give the bounding box of a text using fonts via freetype2</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>imageftbbox</methodname>
<methodparam><type>float</type><parameter>size</parameter></methodparam>
<methodparam><type>float</type><parameter>angle</parameter></methodparam>
<methodparam><type>string</type><parameter>fontfile</parameter></methodparam>
<methodparam><type>string</type><parameter>text</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>extrainfo</parameter></methodparam>
</methodsynopsis>
<para>
This function calculates and returns the bounding box in pixels
for a FreeType text.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>size</parameter></term>
<listitem>
<para>&gd.font.size;</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>angle</parameter></term>
<listitem>
<para>
Angle in degrees in which <parameter>text</parameter> will be
measured.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>fontfile</parameter></term>
<listitem>
<para>
The name of the TrueType font file (can be a URL). Depending on
which version of the GD library that PHP is using, it may attempt to
search for files that do not begin with a leading '/' by appending
'.ttf' to the filename and searching along a library-defined font path.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>text</parameter></term>
<listitem>
<para>
The string to be measured.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>extrainfo</parameter></term>
<listitem>
<para>
<table>
<title>Possible array indexes for <parameter>extrainfo</parameter></title>
<tgroup cols="2">
<thead>
<row>
<entry>Key</entry>
<entry>Type</entry>
<entry>Meaning</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>linespacing</literal></entry>
<entry><type>float</type></entry>
<entry>Defines drawing linespacing</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
<function>imageftbbox</function> returns an array with 8
elements representing four points making the bounding box of the
text:
<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>0</entry>
<entry>lower left corner, X position</entry>
</row>
<row>
<entry>1</entry>
<entry>lower left corner, Y position</entry>
</row>
<row>
<entry>2</entry>
<entry>lower right corner, X position</entry>
</row>
<row>
<entry>3</entry>
<entry>lower right corner, Y position</entry>
</row>
<row>
<entry>4</entry>
<entry>upper right corner, X position</entry>
</row>
<row>
<entry>5</entry>
<entry>upper right corner, Y position</entry>
</row>
<row>
<entry>6</entry>
<entry>upper left corner, X position</entry>
</row>
<row>
<entry>7</entry>
<entry>upper left corner, Y position</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>
The points are relative to the <emphasis>text</emphasis> regardless of the
<parameter>angle</parameter>, so "upper left" means in the top left-hand
corner seeing the text horizontally.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>imageftbbox</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a 300x150 image
$im = imagecreatetruecolor(300, 150);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Set the background to be white
imagefilledrectangle($im, 0, 0, 299, 299, $white);
// Path to our font file
$font = './arial.ttf';
// First we create our bounding box
$bbox = imageftbbox(10, 0, $font, 'The PHP Documentation Group');
// This is our cordinates for X and Y
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
imagefttext($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group');
// Output to browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.gd.2;
&note.freetype;
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>4.3.5</entry>
<entry>
<parameter>extrainfo</parameter> was made optional.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->