Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 10877

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Image 图像函数</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="函数参考"
HREF="funcref.html"><LINK
REL="PREVIOUS"
TITLE="iis_stop_service"
HREF="function.iis-stop-service.html"><LINK
REL="NEXT"
TITLE="gd_info"
HREF="function.gd-info.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="reference"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.iis-stop-service.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.gd-info.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="reference"
><A
NAME="ref.image"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
>LXV. Image 图像函数</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN86159"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="image.intro"
>简介</A
></H1
><P
>&#13;    PHP 不仅限于只产生 HTML 的输出。还可以创建及操作多种不同图像格式的图像文件,包括
    gif,png,jpg,wbmp 和 xpm。更方便的是,PHP
    可以直接将图像流输出到浏览器。要处理图像,需要在编译 PHP 时加上图像函数的 GD 库。GD
    和 PHP 还可能需要其它的库,视乎需要支持哪些图像格式而定。
   </P
><P
>&#13;    可以在 PHP 中使用图像函数来得到
    <ACRONYM
CLASS="acronym"
>JPEG</ACRONYM
>,<ACRONYM
CLASS="acronym"
>GIF</ACRONYM
>,<ACRONYM
CLASS="acronym"
>PNG</ACRONYM
>,<ACRONYM
CLASS="acronym"
>SWF</ACRONYM
>,<ACRONYM
CLASS="acronym"
>TIFF</ACRONYM
>
    和 <ACRONYM
CLASS="acronym"
>JPEG2000</ACRONYM
> 图像的大小。
   </P
><P
>&#13;    <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
      阅读需求一节以了解怎样扩展图像能力来读取,写入和修改图像以及读取数码相机拍摄的照片中的元数据。
     </P
></BLOCKQUOTE
></DIV
>
   </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="image.requirements"
>需求</A
></H1
><P
>&#13;    如果有 <ACRONYM
CLASS="acronym"
>GD</ACRONYM
> 库(在 <A
HREF="http://www.libgd.org/"
TARGET="_top"
>http://www.libgd.org/</A
>),可以创建及操作图像。
   </P
><P
>&#13;    所能处理的图像格式取决于所安装的 <ACRONYM
CLASS="acronym"
>GD</ACRONYM
>
    版本,以及其它 <ACRONYM
CLASS="acronym"
>GD</ACRONYM
> 可能用到的来访问这些图像格式的库。低于
    gd-1.6 版本的 <ACRONYM
CLASS="acronym"
>GD</ACRONYM
> 支持 GIF 图像格式,不支持
    PNG,高于 gd-1.6 低于 gd-2.0.28 的版本支持 PNG,不支持 GIF。在
    gd-2.0.28 中又重新支持 GIF 了。
    <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
      自 PHP 4.3 起绑定了一个 GD
      库的版本。这个绑定的版本具有一些附加的特色例如透明混色,应优先使用此版本,因为它的代码维护得更好以及更加稳定。
     </P
></BLOCKQUOTE
></DIV
>
   </P
><P
>&#13;    可能想要增加 GD 处理的图像格式。
    <DIV
CLASS="table"
><A
NAME="AEN86185"
></A
><P
><B
>表 1. 所支持的图像格式</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>图像格式</TH
><TH
>要下载的库</TH
><TH
>注解</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="literal"
>gif</TT
></TD
><TD
>&nbsp;</TD
><TD
>&#13;         仅在低于 gd-1.6 与高于 gd-2.0.28 的 GD 版本中支持。PHP 4.3.0 以及绑定的 GD
         库中支持<SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>只读</I
></SPAN
>的 GIF。PHP 4.3.9 和 PHP 5.0.1
         起支持<SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>写入</I
></SPAN
>。
        </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>jpeg-6b</TT
></TD
><TD
><A
HREF="ftp://ftp.uu.net/graphics/jpeg/"
TARGET="_top"
>ftp://ftp.uu.net/graphics/jpeg/</A
></TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>png</TT
></TD
><TD
><A
HREF="http://www.libpng.org/pub/png/libpng.html"
TARGET="_top"
>http://www.libpng.org/pub/png/libpng.html</A
></TD
><TD
>&#13;         仅在高于 gd-1.6 的 GD 版本中支持。
        </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>xpm</TT
></TD
><TD
><A
HREF="ftp://metalab.unc.edu/pub/Linux/libs/X/!INDEX.html"
TARGET="_top"
>ftp://metalab.unc.edu/pub/Linux/libs/X/!INDEX.html</A
></TD
><TD
>&#13;         如果系统中安装了 X 环境,则很可能已经有了这个库。
        </TD
></TR
></TBODY
></TABLE
></DIV
>
   </P
><P
>&#13;    可能想要增强 GD 处理不同字体的能力。支持下列字库:
    <DIV
CLASS="table"
><A
NAME="AEN86220"
></A
><P
><B
>表 2. 所支持的字库</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>字库</TH
><TH
>下载位置</TH
><TH
>注解</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="literal"
>FreeType 1.x</TT
></TD
><TD
><A
HREF="http://www.freetype.org/"
TARGET="_top"
>http://www.freetype.org/</A
></TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>FreeType 2</TT
></TD
><TD
><A
HREF="http://www.freetype.org/"
TARGET="_top"
>http://www.freetype.org/</A
></TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>T1lib</TT
></TD
><TD
><A
HREF="ftp://sunsite.unc.edu/pub/Linux/libs/graphics/"
TARGET="_top"
>ftp://sunsite.unc.edu/pub/Linux/libs/graphics/</A
>)</TD
><TD
>&#13;         支持 Type 1 字体。
        </TD
></TR
></TBODY
></TABLE
></DIV
>
   </P
><P
>&#13;    如果 PHP 编译时指定了
    <CODE
CLASS="option"
>--enable-exif</CODE
>,就可以操作存储于
    <ACRONYM
CLASS="acronym"
>JPEG</ACRONYM
> 和 <ACRONYM
CLASS="acronym"
>TIFF</ACRONYM
>
    图像文件头中的信息。这样就可以读取上面提到的数码相机生成的照片中的元数据。这些函数不需要
    <ACRONYM
CLASS="acronym"
>GD</ACRONYM
> 库。
   </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="image.installation"
>安装</A
></H1
><P
>&#13;  要激活 GD 支持,配置 PHP 时加上
  <CODE
CLASS="option"
>--with-gd[=DIR]</CODE
>,DIR 是 GD
  的基本安装目录。要使用推荐的绑定的 GD 库版本(首次绑定于 PHP 4.3.0),使用
  <CODE
CLASS="option"
>--with-gd</CODE
>。要编译
  GD 库,需要<SPAN
CLASS="productname"
>libpng</SPAN
> 和 <SPAN
CLASS="productname"
>libjpeg</SPAN
>。
 </P
><P
>&#13;  在 Windows 中,需要将 GD2 的 DLL 文件 <TT
CLASS="filename"
>php_gd2.dll</TT
>
  作为一个扩展包含在 <TT
CLASS="filename"
>php.ini</TT
> 中。GD1 的 DLL 文件
  <TT
CLASS="filename"
>php_gd.dll</TT
> 在 PHP 4.3.2
  中被删除了。此外要注意首选的真彩色图像函数,例如
  <A
HREF="function.imagecreatetruecolor.html"
><B
CLASS="function"
>imagecreatetruecolor()</B
></A
>,需要 GD2。
 </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
   要在 Windows 下启用 exif,在 <TT
CLASS="filename"
>php.ini</TT
> 中 php_mbstring.dll 必须在
   php_exif.dll 之前加载。
  </P
></BLOCKQUOTE
></DIV
><P
>&#13;  要在 <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>PHP 3</I
></SPAN
> 中禁止 GD 支持,在配置时加上
  <CODE
CLASS="option"
>--without-gd</CODE
>。
 </P
><P
>&#13;  要增强 GD 的能力以处理更多的图像格式,在配置 PHP 时指定
  <TT
CLASS="literal"
>--with-XXXX</TT
> 的配置开关。
  <DIV
CLASS="table"
><A
NAME="AEN86272"
></A
><P
><B
>表 3. 所支持的图像格式</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>图像格式</TH
><TH
>配置开关</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="literal"
>jpeg-6b</TT
></TD
><TD
>&#13;       要激活 jpeg-6b 的支持,加上
       <CODE
CLASS="option"
>--with-jpeg-dir=DIR</CODE
>.
      </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>png</TT
></TD
><TD
>&#13;       要激活 png 的支持,加上
       <CODE
CLASS="option"
>--with-png-dir=DIR</CODE
>。注意,libpng
       需要 <A
HREF="ref.zlib.html#zlib.requirements"
>zlib library</A
>,因此配置中还要加上
       <CODE
CLASS="option"
>--with-zlib-dir[=DIR]</CODE
>。
      </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>xpm</TT
></TD
><TD
>&#13;       要激活 xpm 的支持,加上
       <CODE
CLASS="option"
>--with-xpm-dir=DIR</CODE
>。如果配置时提示找不到所需要的库,可以加上到
       X11 库的路径。
      </TD
></TR
></TBODY
></TABLE
></DIV
>
  <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
    当把 PHP 和 libpng 一起编译时,必须使用和 GD 库连接的同一个版本。
   </P
></BLOCKQUOTE
></DIV
>
 </P
><P
>&#13;  要增强 GD 的能力以处理更多的字体,在配置 PHP 时指定
  <TT
CLASS="literal"
>--with-XXXX</TT
> 的配置开关。
  <DIV
CLASS="table"
><A
NAME="AEN86301"
></A
><P
><B
>表 4. 所支持的字库</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>字库</TH
><TH
>配置开关</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="literal"
>FreeType 1.x</TT
></TD
><TD
>&#13;       要激活 FreeType 1.x 的支持,加上
       <CODE
CLASS="option"
>--with-ttf[=DIR]</CODE
>。
      </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>FreeType 2</TT
></TD
><TD
>&#13;       要激活 FreeType 2 的支持,加上
       <CODE
CLASS="option"
>--with-freetype-dir=DIR</CODE
>。
      </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>T1lib</TT
></TD
><TD
>&#13;       要激活 T1lib(Type 1 字体),加上
       <CODE
CLASS="option"
>--with-t1lib[=DIR]</CODE
>。
      </TD
></TR
><TR
><TD
><TT
CLASS="literal"
>本地 TrueType 字符串函数</TT
></TD
><TD
>&#13;       要激活本地 TrueType 字符串函数的支持,加上
       <CODE
CLASS="option"
>--enable-gd-native-ttf</CODE
>。
      </TD
></TR
></TBODY
></TABLE
></DIV
>
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="image.configuration"
>运行时配置</A
></H1
><P
>&#13;  没有 image 特定的配置选项。不过可以参考
  <A
HREF="ref.exif.html"
>exif 扩展库</A
>配置指令。
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="image.resources"
>资源类型</A
></H1
><P
>本扩展模块未定义任何资源类型。</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="image.constants"
>预定义常量</A
></H1
><P
>以下常量由本扩展模块定义,因此只有在本扩展模块被编译到
PHP 中,或者在运行时被动态加载后才有效。</P
><P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="constant"
><B
>IMG_GIF</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_JPG</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_JPEG</B
></TT
>
     (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_PNG</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_WBMP</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_XPM</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_COLOR_TILED</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_COLOR_STYLED</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_COLOR_BRUSHED</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_COLOR_STYLEDBRUSHED</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_COLOR_TRANSPARENT</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_ARC_ROUNDED</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_ARC_PIE</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_ARC_CHORD</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_ARC_NOFILL</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMG_ARC_EDGED</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_GIF</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_JPEG</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_PNG</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_SWF</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_PSD</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_BMP</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_WBMP</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_XBM</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_TIFF_II</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_TIFF_MM</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_IFF</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_JB2</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_JPC</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_JP2</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_JPX</B
></TT
>
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;
    </P
></DD
><DT
><TT
CLASS="constant"
><B
>IMAGETYPE_SWC</B
></TT
> 
    (<A
HREF="language.types.integer.html"
><B
CLASS="type"
>integer</B
></A
>)</DT
><DD
><P
>&#13;     
    </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="image.examples"
>范例</A
></H1
><P
>&#13;    <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN86535"
></A
><P
><B
>例 1. 用 PHP 创建 PNG 图像</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /><br />header</font><font color="#007700">(</font><font color="#DD0000">"Content-type: image/png"</font><font color="#007700">);<br /></font><font color="#0000BB">$string </font><font color="#007700">= </font><font color="#0000BB">$_GET</font><font color="#007700">[</font><font color="#DD0000">'text'</font><font color="#007700">];<br /></font><font color="#0000BB">$im&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">= </font><font color="#0000BB">imagecreatefrompng</font><font color="#007700">(</font><font color="#DD0000">"images/button1.png"</font><font color="#007700">);<br /></font><font color="#0000BB">$orange </font><font color="#007700">= </font><font color="#0000BB">imagecolorallocate</font><font color="#007700">(</font><font color="#0000BB">$im</font><font color="#007700">, </font><font color="#0000BB">220</font><font color="#007700">, </font><font color="#0000BB">210</font><font color="#007700">, </font><font color="#0000BB">60</font><font color="#007700">);<br /></font><font color="#0000BB">$px&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">= (</font><font color="#0000BB">imagesx</font><font color="#007700">(</font><font color="#0000BB">$im</font><font color="#007700">) - </font><font color="#0000BB">7.5 </font><font color="#007700">* </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$string</font><font color="#007700">)) / </font><font color="#0000BB">2</font><font color="#007700">;<br /></font><font color="#0000BB">imagestring</font><font color="#007700">(</font><font color="#0000BB">$im</font><font color="#007700">, </font><font color="#0000BB">3</font><font color="#007700">, </font><font color="#0000BB">$px</font><font color="#007700">, </font><font color="#0000BB">9</font><font color="#007700">, </font><font color="#0000BB">$string</font><font color="#007700">, </font><font color="#0000BB">$orange</font><font color="#007700">);<br /></font><font color="#0000BB">imagepng</font><font color="#007700">(</font><font color="#0000BB">$im</font><font color="#007700">);<br /></font><font color="#0000BB">imagedestroy</font><font color="#007700">(</font><font color="#0000BB">$im</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    本例应该在一个具有类似:&#60;img
    src="button.php?text=text"&#62; 标记的页面中被调用。上述的
    button.php 脚本会取得
    "text" 字符串将其覆盖在原图上(本例中的
    "images/button1.png")并输出作为结果的图像。用此方法可以很方便地修改按钮上的文字从而避免了每次都要新画一个按钮的图像。用此方法就可以动态生成了。
   </P
></DIV
></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>目录</B
></DT
><DT
><A
HREF="function.gd-info.html"
>gd_info</A
>&nbsp;--&nbsp;取得当前安装的 GD 库的信息</DT
><DT
><A
HREF="function.getimagesize.html"
>getimagesize</A
>&nbsp;--&nbsp;取得图像大小</DT
><DT
><A
HREF="function.image-type-to-extension.html"
>image_type_to_extension</A
>&nbsp;--&nbsp;取得图像类型的文件后缀</DT
><DT
><A
HREF="function.image-type-to-mime-type.html"
>image_type_to_mime_type</A
>&nbsp;--&nbsp;取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype
    所返回的图像类型的 MIME 类型</DT
><DT
><A
HREF="function.image2wbmp.html"
>image2wbmp</A
>&nbsp;--&nbsp;以 WBMP 格式将图像输出到浏览器或文件</DT
><DT
><A
HREF="function.imagealphablending.html"
>imagealphablending</A
>&nbsp;--&nbsp;设定图像的混色模式</DT
><DT
><A
HREF="function.imageantialias.html"
>imageantialias</A
>&nbsp;--&nbsp;是否使用抗锯齿(antialias)功能</DT
><DT
><A
HREF="function.imagearc.html"
>imagearc</A
>&nbsp;--&nbsp;画椭圆弧</DT
><DT
><A
HREF="function.imagechar.html"
>imagechar</A
>&nbsp;--&nbsp;水平地画一个字符</DT
><DT
><A
HREF="function.imagecharup.html"
>imagecharup</A
>&nbsp;--&nbsp;垂直地画一个字符</DT
><DT
><A
HREF="function.imagecolorallocate.html"
>imagecolorallocate</A
>&nbsp;--&nbsp;为一幅图像分配颜色</DT
><DT
><A
HREF="function.imagecolorallocatealpha.html"
>imagecolorallocatealpha</A
>&nbsp;--&nbsp;为一幅图像分配颜色 + alpha</DT
><DT
><A
HREF="function.imagecolorat.html"
>imagecolorat</A
>&nbsp;--&nbsp;取得某像素的颜色索引值</DT
><DT
><A
HREF="function.imagecolorclosest.html"
>imagecolorclosest</A
>&nbsp;--&nbsp;取得与指定的颜色最接近的颜色的索引值</DT
><DT
><A
HREF="function.imagecolorclosestalpha.html"
>imagecolorclosestalpha</A
>&nbsp;--&nbsp;取得与指定的颜色加透明度最接近的颜色</DT
><DT
><A
HREF="function.imagecolorclosesthwb.html"
>imagecolorclosesthwb</A
>&nbsp;--&nbsp;
     取得与给定颜色最接近的色度的黑白色的索引
    </DT
><DT
><A
HREF="function.imagecolordeallocate.html"
>imagecolordeallocate</A
>&nbsp;--&nbsp;取消图像颜色的分配</DT
><DT
><A
HREF="function.imagecolorexact.html"
>imagecolorexact</A
>&nbsp;--&nbsp;取得指定颜色的索引值</DT
><DT
><A
HREF="function.imagecolorexactalpha.html"
>imagecolorexactalpha</A
>&nbsp;--&nbsp;取得指定的颜色加透明度的索引值</DT
><DT
><A
HREF="function.imagecolormatch.html"
>imagecolormatch</A
>&nbsp;--&nbsp;使一个图像中调色板版本的颜色与真彩色版本更能匹配</DT
><DT
><A
HREF="function.imagecolorresolve.html"
>imagecolorresolve</A
>&nbsp;--&nbsp;取得指定颜色的索引值或有可能得到的最接近的替代值</DT
><DT
><A
HREF="function.imagecolorresolvealpha.html"
>imagecolorresolvealpha</A
>&nbsp;--&nbsp;
    取得指定颜色 + alpha 的索引值或有可能得到的最接近的替代值
   </DT
><DT
><A
HREF="function.imagecolorset.html"
>imagecolorset</A
>&nbsp;--&nbsp;给指定调色板索引设定颜色</DT
><DT
><A
HREF="function.imagecolorsforindex.html"
>imagecolorsforindex</A
>&nbsp;--&nbsp;取得某索引的颜色</DT
><DT
><A
HREF="function.imagecolorstotal.html"
>imagecolorstotal</A
>&nbsp;--&nbsp;取得一幅图像的调色板中颜色的数目</DT
><DT
><A
HREF="function.imagecolortransparent.html"
>imagecolortransparent</A
>&nbsp;--&nbsp;将某个颜色定义为透明色</DT
><DT
><A
HREF="function.imageconvolution.html"
>imageconvolution</A
>&nbsp;--&nbsp;用系数 div 和 offset 申请一个 3x3 的卷积矩阵</DT
><DT
><A
HREF="function.imagecopy.html"
>imagecopy</A
>&nbsp;--&nbsp;拷贝图像的一部分</DT
><DT
><A
HREF="function.imagecopymerge.html"
>imagecopymerge</A
>&nbsp;--&nbsp;拷贝并合并图像的一部分</DT
><DT
><A
HREF="function.imagecopymergegray.html"
>imagecopymergegray</A
>&nbsp;--&nbsp;用灰度拷贝并合并图像的一部分</DT
><DT
><A
HREF="function.imagecopyresampled.html"
>imagecopyresampled</A
>&nbsp;--&nbsp;重采样拷贝部分图像并调整大小</DT
><DT
><A
HREF="function.imagecopyresized.html"
>imagecopyresized</A
>&nbsp;--&nbsp;拷贝部分图像并调整大小</DT
><DT
><A
HREF="function.imagecreate.html"
>imagecreate</A
>&nbsp;--&nbsp;新建一个基于调色板的图像</DT
><DT
><A
HREF="function.imagecreatefromgd2.html"
>imagecreatefromgd2</A
>&nbsp;--&nbsp;从 GD2 文件或 URL 新建一图像</DT
><DT
><A
HREF="function.imagecreatefromgd2part.html"
>imagecreatefromgd2part</A
>&nbsp;--&nbsp;从给定的 GD2 文件或 URL 中的部分新建一图像</DT
><DT
><A
HREF="function.imagecreatefromgd.html"
>imagecreatefromgd</A
>&nbsp;--&nbsp;从 GD 文件或 URL 新建一图像</DT
><DT
><A
HREF="function.imagecreatefromgif.html"
>imagecreatefromgif</A
>&nbsp;--&nbsp;从 GIF 文件或 URL 新建一图像</DT
><DT
><A
HREF="function.imagecreatefromjpeg.html"
>imagecreatefromjpeg</A
>&nbsp;--&nbsp;从 JPEG 文件或 URL 新建一图像</DT
><DT
><A
HREF="function.imagecreatefrompng.html"
>imagecreatefrompng</A
>&nbsp;--&nbsp;从 PNG 文件或 URL 新建一图像</DT
><DT
><A
HREF="function.imagecreatefromstring.html"
>imagecreatefromstring</A
>&nbsp;--&nbsp;从字符串中的图像流新建一图像</DT
><DT
><A
HREF="function.imagecreatefromwbmp.html"
>imagecreatefromwbmp</A
>&nbsp;--&nbsp;从 WBMP 文件或 URL 新建一图像</DT
><DT
><A
HREF="function.imagecreatefromxbm.html"
>imagecreatefromxbm</A
>&nbsp;--&nbsp;从 XBM 文件或 URL 新建一图像</DT
><DT
><A
HREF="function.imagecreatefromxpm.html"
>imagecreatefromxpm</A
>&nbsp;--&nbsp;从 XPM 文件或 URL 新建一图像</DT
><DT
><A
HREF="function.imagecreatetruecolor.html"
>imagecreatetruecolor</A
>&nbsp;--&nbsp;新建一个真彩色图像</DT
><DT
><A
HREF="function.imagedashedline.html"
>imagedashedline</A
>&nbsp;--&nbsp;画一虚线</DT
><DT
><A
HREF="function.imagedestroy.html"
>imagedestroy</A
>&nbsp;--&nbsp;销毁一图像</DT
><DT
><A
HREF="function.imageellipse.html"
>imageellipse</A
>&nbsp;--&nbsp;画一个椭圆</DT
><DT
><A
HREF="function.imagefill.html"
>imagefill</A
>&nbsp;--&nbsp;区域填充</DT
><DT
><A
HREF="function.imagefilledarc.html"
>imagefilledarc</A
>&nbsp;--&nbsp;画一椭圆弧且填充</DT
><DT
><A
HREF="function.imagefilledellipse.html"
>imagefilledellipse</A
>&nbsp;--&nbsp;画一椭圆并填充</DT
><DT
><A
HREF="function.imagefilledpolygon.html"
>imagefilledpolygon</A
>&nbsp;--&nbsp;画一多边形并填充</DT
><DT
><A
HREF="function.imagefilledrectangle.html"
>imagefilledrectangle</A
>&nbsp;--&nbsp;画一矩形并填充</DT
><DT
><A
HREF="function.imagefilltoborder.html"
>imagefilltoborder</A
>&nbsp;--&nbsp;区域填充到指定颜色的边界为止</DT
><DT
><A
HREF="function.imagefilter.html"
>imagefilter</A
>&nbsp;--&nbsp;对图像使用过滤器</DT
><DT
><A
HREF="function.imagefontheight.html"
>imagefontheight</A
>&nbsp;--&nbsp;取得字体高度</DT
><DT
><A
HREF="function.imagefontwidth.html"
>imagefontwidth</A
>&nbsp;--&nbsp;取得字体宽度</DT
><DT
><A
HREF="function.imageftbbox.html"
>imageftbbox</A
>&nbsp;--&nbsp;给出一个使用 FreeType 2 字体的文本框</DT
><DT
><A
HREF="function.imagefttext.html"
>imagefttext</A
>&nbsp;--&nbsp;使用 FreeType 2 字体将文本写入图像</DT
><DT
><A
HREF="function.imagegammacorrect.html"
>imagegammacorrect</A
>&nbsp;--&nbsp;对 GD 图像应用 gamma 修正</DT
><DT
><A
HREF="function.imagegd2.html"
>imagegd2</A
>&nbsp;--&nbsp;将 GD2 图像输出到浏览器或文件</DT
><DT
><A
HREF="function.imagegd.html"
>imagegd</A
>&nbsp;--&nbsp;将 GD 图像输出到浏览器或文件</DT
><DT
><A
HREF="function.imagegif.html"
>imagegif</A
>&nbsp;--&nbsp;以 GIF 格式将图像输出到浏览器或文件</DT
><DT
><A
HREF="function.imageinterlace.html"
>imageinterlace</A
>&nbsp;--&nbsp;激活或禁止隔行扫描</DT
><DT
><A
HREF="function.imageistruecolor.html"
>imageistruecolor</A
>&nbsp;--&nbsp;检查图像是否为真彩色图像</DT
><DT
><A
HREF="function.imagejpeg.html"
>imagejpeg</A
>&nbsp;--&nbsp;以 JPEG 格式将图像输出到浏览器或文件</DT
><DT
><A
HREF="function.imagelayereffect.html"
>imagelayereffect</A
>&nbsp;--&nbsp;设定 alpha 混色标志以使用绑定的 libgd 分层效果
  </DT
><DT
><A
HREF="function.imageline.html"
>imageline</A
>&nbsp;--&nbsp;画一条线段</DT
><DT
><A
HREF="function.imageloadfont.html"
>imageloadfont</A
>&nbsp;--&nbsp;载入一新字体</DT
><DT
><A
HREF="function.imagepalettecopy.html"
>imagepalettecopy</A
>&nbsp;--&nbsp;将调色板从一幅图像拷贝到另一幅</DT
><DT
><A
HREF="function.imagepng.html"
>imagepng</A
>&nbsp;--&nbsp;以 PNG 格式将图像输出到浏览器或文件</DT
><DT
><A
HREF="function.imagepolygon.html"
>imagepolygon</A
>&nbsp;--&nbsp;画一个多边形</DT
><DT
><A
HREF="function.imagepsbbox.html"
>imagepsbbox</A
>&nbsp;--&nbsp;给出一个使用 PostScript Type1 字体的文本方框</DT
><DT
><A
HREF="function.imagepsencodefont.html"
>imagepsencodefont</A
>&nbsp;--&nbsp;改变字体中的字符编码矢量</DT
><DT
><A
HREF="function.imagepsextendfont.html"
>imagepsextendfont</A
>&nbsp;--&nbsp;扩充或精简字体</DT
><DT
><A
HREF="function.imagepsfreefont.html"
>imagepsfreefont</A
>&nbsp;--&nbsp;释放一个 PostScript Type 1 字体所占用的内存</DT
><DT
><A
HREF="function.imagepsloadfont.html"
>imagepsloadfont</A
>&nbsp;--&nbsp;从文件中加载一个 PostScript Type 1 字体</DT
><DT
><A
HREF="function.imagepsslantfont.html"
>imagepsslantfont</A
>&nbsp;--&nbsp;倾斜某字体</DT
><DT
><A
HREF="function.imagepstext.html"
>imagepstext</A
>&nbsp;--&nbsp;用 PostScript Type1 字体把文本字符串画在图像上</DT
><DT
><A
HREF="function.imagerectangle.html"
>imagerectangle</A
>&nbsp;--&nbsp;画一个矩形</DT
><DT
><A
HREF="function.imagerotate.html"
>imagerotate</A
>&nbsp;--&nbsp;用给定角度旋转图像</DT
><DT
><A
HREF="function.imagesavealpha.html"
>imagesavealpha</A
>&nbsp;--&nbsp;设置标记以在保存 PNG 图像时保存完整的 alpha 通道信息(与单一透明色相反)</DT
><DT
><A
HREF="function.imagesetbrush.html"
>imagesetbrush</A
>&nbsp;--&nbsp;设定画线用的画笔图像</DT
><DT
><A
HREF="function.imagesetpixel.html"
>imagesetpixel</A
>&nbsp;--&nbsp;画一个单一像素</DT
><DT
><A
HREF="function.imagesetstyle.html"
>imagesetstyle</A
>&nbsp;--&nbsp;设定画线的风格</DT
><DT
><A
HREF="function.imagesetthickness.html"
>imagesetthickness</A
>&nbsp;--&nbsp;设定画线的宽度</DT
><DT
><A
HREF="function.imagesettile.html"
>imagesettile</A
>&nbsp;--&nbsp;设定用于填充的贴图</DT
><DT
><A
HREF="function.imagestring.html"
>imagestring</A
>&nbsp;--&nbsp;水平地画一行字符串</DT
><DT
><A
HREF="function.imagestringup.html"
>imagestringup</A
>&nbsp;--&nbsp;垂直地画一行字符串</DT
><DT
><A
HREF="function.imagesx.html"
>imagesx</A
>&nbsp;--&nbsp;取得图像宽度</DT
><DT
><A
HREF="function.imagesy.html"
>imagesy</A
>&nbsp;--&nbsp;取得图像高度</DT
><DT
><A
HREF="function.imagetruecolortopalette.html"
>imagetruecolortopalette</A
>&nbsp;--&nbsp;将真彩色图像转换为调色板图像</DT
><DT
><A
HREF="function.imagettfbbox.html"
>imagettfbbox</A
>&nbsp;--&nbsp;取得使用 TrueType 字体的文本的范围</DT
><DT
><A
HREF="function.imagettftext.html"
>imagettftext</A
>&nbsp;--&nbsp;用 TrueType 字体向图像写入文本</DT
><DT
><A
HREF="function.imagetypes.html"
>imagetypes</A
>&nbsp;--&nbsp;返回当前 PHP 版本所支持的图像类型</DT
><DT
><A
HREF="function.imagewbmp.html"
>imagewbmp</A
>&nbsp;--&nbsp;以 WBMP 格式将图像输出到浏览器或文件</DT
><DT
><A
HREF="function.imagexbm.html"
>imagexbm</A
>&nbsp;--&nbsp;将 XBM 图像输出到浏览器或文件</DT
><DT
><A
HREF="function.iptcembed.html"
>iptcembed</A
>&nbsp;--&nbsp;将二进制 IPTC 数据嵌入到一幅 JPEG 图像中</DT
><DT
><A
HREF="function.iptcparse.html"
>iptcparse</A
>&nbsp;--&nbsp;
     将二进制 IPTC <A
HREF="http://www.iptc.org/"
TARGET="_top"
>http://www.iptc.org/</A
> 块解析为单个标记
    </DT
><DT
><A
HREF="function.jpeg2wbmp.html"
>jpeg2wbmp</A
>&nbsp;--&nbsp;将 JPEG 图像文件转换为 WBMP 图像文件</DT
><DT
><A
HREF="function.png2wbmp.html"
>png2wbmp</A
>&nbsp;--&nbsp;将 PNG 图像文件转换为 WBMP 图像文件</DT
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.iis-stop-service.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.gd-info.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>iis_stop_service</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="funcref.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>gd_info</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>