图片GD底层类

属性
命名空间 fize\image
类名 Gd
方法:
方法名 说明
__construct() 初始化
__destruct() 析构,释放内存
info() 取得当前安装的 GD 库的信息
getSize() 取得图像大小
getType() 获取图片真实后缀
getSizeFromString() 从字符串中获取图像尺寸信息
typeToExtension() 取得图像类型的文件后缀
typeToMimeType() 返回的图像类型的 MIME 类型
output() 输出图像
affine() 仿射变换
affineMatrixConcat() 连接两个仿射变换矩阵
affineMatrixGet() 得到一个仿射变换矩阵
alphaBlending() 设定图像的混色模式
antialias() 是否使用抗锯齿功能
arc() 画椭圆弧
char() 水平地画一个字符
charUp() 垂直地画一个字符
colorAllocate() 分配颜色
colorAllocateAlpha() 分配带透明度颜色
colorAt() 取得某像素的颜色索引
colorClosest() 取得与指定的颜色最接近的颜色索引
colorClosestAlpha() 取得与指定的颜色加透明度最接近的颜色索引
colorClosestHwb() 取得与给定颜色最接近的色度的黑白色的索引
colorDeallocate() 取消图像颜色分配
colorExact() 取得指定颜色的索引值
colorExactAlpha() 取得指定的颜色加透明度的索引值
colorMatch() 使一个图像中调色板版本的颜色与真彩色版本更能匹配
colorResolve() 取得指定颜色的索引值或有可能得到的最接近的替代值
colorResolveAlpha() 取得指定颜色 + alpha 的索引值或有可能得到的最接近的替代值
colorSet() 给指定调色板索引设定颜色
colorsForIndex() 取得颜色索引的信息
colorStotal() 取得一幅图像的调色板中颜色的数目
colorTransparent() 将某个颜色定义为透明色
convolution() 用系数 div 和 offset 申请一个 3x3 的卷积矩阵
copy() 拷贝图像的一部分
copyMerge() 拷贝并合并图像的一部分
copyMergeGray() 用灰度拷贝并合并图像的一部分
copyResampled() 重采样拷贝部分图像并调整大小
copyResized() 拷贝部分图像并调整大小
create() 新建一个基于调色板的图像
createFrom() 从指定资源创建
crop() 裁剪图像
cropAuto() 使用其中一种可用模式自动裁剪图像
dashedLine() 画一虚线
destroy() 销毁一图像
ellipse() 画一个椭圆
fill() 区域填充,即与 x, y 点颜色相同且相邻的点都会被填充
filledArc() 画一椭圆弧且填充
filledEllipse() 画一椭圆并填充
filledPolygon() 画一多边形并填充
filledRectangle() 画一矩形并填充
fillToBorder() 区域填充到指定颜色的边界为止
filter() 使用过滤器
flip() 使用给定模式翻转图像
fontHeight() 取得字体高度
fontWidth() 取得字体宽度
ftbbox() 给出一个使用 FreeType 2 字体的文本框
fttext() 使用 FreeType 2 字体将文本写入图像
gammaCorrect() 对 GD 图像应用 gamma 修正
getClip() 取得剪切矩形
grabScreen() 捕捉整个屏幕
grabWindow() 捕捉指定窗口
interlace() 激活或禁止隔行扫描
isTrueColor() 检查图像是否为真彩色图像
layerEffect() 设定 alpha 混色标志以使用绑定的 libgd 分层效果
line() 画一条线段
loadFont() 载入新字体
openPolygon() 绘制一个开放多边形
paletteCopy() 将调色板从一幅图像拷贝到另一幅
paletteToTrueColor() 将基于调色板的图像转换为真颜色
polygon() 画一个多边形
psbbox() 给出一个使用 PostScript Type1 字体的文本方框
psEncodeFont() 改变字体中的字符编码矢量
psExtendFont() 扩充或精简字体
psFreeFont() 释放一个 PostScript Type 1 字体所占用的内存
psLoadFont() 从文件中加载一个 PostScript Type 1 字体
psSlantFont() 倾斜某字体
psText() 用 PostScript Type1 字体把文本字符串画在图像上
rectangle() 画一个矩形
resolution() 获取或设置图像的分辨率
rotate() 用给定角度旋转图像
saveAlpha() 设置标记以在保存 PNG 图像时保存完整的 alpha 通道信息(与单一透明色相反)
scale() 使用给定的新宽度和高度缩放图像
setBrush() 设定画线用的画笔图像
setClip() 设置剪切矩形
setInterpolation() 设置插值方法
setPixel() 画一个单一像素
setStyle() 设定画线的风格
setThickness() 设定画线的宽度
setTile() 设定用于填充的贴图
stringHorizontal() 水平地画一行字符串
stringUp() 垂直地画一行字符串
sx() 取得图像宽度
sy() 取得图像高度
trueColorToPalette() 将真彩色图像转换为调色板图像
ttfbbox() 取得使用 TrueType 字体的文本的范围
ttftext() 用 TrueType 字体向图像写入文本
types() 返回当前 PHP 版本所支持的图像类型
iptcEmbed() 将二进制 IPTC 数据嵌入到一幅 JPEG 图像中
iptcParse() 将二进制 IPTC 块解析为单个标记
jpeg2Wbmp() 将 JPEG 图像文件转换为 WBMP 图像文件
png2Wbmp() 将 PNG 图像文件转换为 WBMP 图像文件

方法

__construct()

初始化

public function __construct (
    string $filename = null,
    string $from = null,
    array $options = []
)
参数:
名称 说明
filename 指定图片路径,为null表示不指定
from 从指定资源创建
options 额外选项
参数 `$options` :
$filename为null时,该参数必须指定

__destruct()

析构,释放内存

public function __destruct ()

info()

取得当前安装的 GD 库的信息

public static function info () : array

getSize()

取得图像大小

public function getSize (
    array &$imageinfo = null
) : array
参数:
名称 说明
imageinfo  

getType()

获取图片真实后缀

public function getType () : string

getSizeFromString()

从字符串中获取图像尺寸信息

public static function getSizeFromString (
    string $imagedata,
    array &$imageinfo = null
) : array
参数:
名称 说明
imagedata  
imageinfo  

typeToExtension()

取得图像类型的文件后缀

public static function typeToExtension (
    int $imagetype,
    bool $include_dot = false
) : string
参数:
名称 说明
imagetype IMAGETYPE_XXX 系列常量之一。
include_dot 是否在后缀名前加一个点。

typeToMimeType()

返回的图像类型的 MIME 类型

public static function typeToMimeType (
    int $imagetype
) : string
参数:
名称 说明
imagetype IMAGETYPE_XXX 系列常量之一。

output()

输出图像

public function output (
    string $type = null,
    string $filename = null,
    array $options = []
) : bool
参数:
名称 说明
type 输出类型
filename 指定输出文件路径,不指定则直接在浏览器显示
options 可选的参数
返回值:

如果是直接显示图像则返回null

affine()

仿射变换

public function affine (
    array $affine,
    array $clip = null
) : resource
参数:
名称 说明
affine [ a0, b0, a1, b1, a2, b2 ]
clip 剪切区域
返回值:

失败时返回false

参数 `$clip` :
其中键为 "x""y""width"  "height"

affineMatrixConcat()

连接两个仿射变换矩阵

public static function affineMatrixConcat (
    array $m1,
    array $m2
) : array
参数:
名称 说明
m1 仿射变换矩阵1
m2 仿射变换矩阵2
返回值:

失败返回false

affineMatrixGet()

得到一个仿射变换矩阵

public static function affineMatrixGet (
    int $type,
    mixed $options = null
) : array
参数:
名称 说明
type 常量IMG_AFFINE_*
options 其他选项
返回值:

失败返回false

alphaBlending()

设定图像的混色模式

public function alphaBlending (
    bool $blendmode
) : bool
参数:
名称 说明
blendmode 启用或禁用

antialias()

是否使用抗锯齿功能

public function antialias (
    bool $enabled
) : bool
参数:
名称 说明
enabled 启用或禁用

arc()

画椭圆弧

public function arc (
    int $cx,
    int $cy,
    int $width,
    int $height,
    int $start,
    int $end,
    int $color
) : bool
参数:
名称 说明
cx 中心点x轴坐标
cy 中心点y轴坐标
width 椭圆宽度
height 椭圆高度
start 起点角度
end 结束点角度
color 配色识符
参数 `$start` :
  0°位于三点钟位置,以顺时针方向绘画。
参数 `$end` :
  0°位于三点钟位置,以顺时针方向绘画。

char()

水平地画一个字符

public function char (
    int $font,
    int $x,
    int $y,
    string $c,
    int $color
) : bool
参数:
名称 说明
font 更大的数字对应于更大的字体
x 左上角x轴坐标
y 左上角y轴坐标
c 字符串
color 配色识符

charUp()

垂直地画一个字符

public function charUp (
    int $font,
    int $x,
    int $y,
    string $c,
    int $color
) : bool
参数:
名称 说明
font 更大的数字对应于更大的字体
x 左上角x轴坐标
y 左上角y轴坐标
c 字符串
color 配色识符

colorAllocate()

分配颜色

public function colorAllocate (
    int $red,
    int $green,
    int $blue
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]
返回值:

成功返回配色识符,失败返回false

colorAllocateAlpha()

分配带透明度颜色

public function colorAllocateAlpha (
    int $red,
    int $green,
    int $blue,
    int $alpha
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]
alpha 透明度[0 ~ 127]
返回值:

成功返回配色识符,失败返回false

colorAt()

取得某像素的颜色索引

public function colorAt (
    int $x,
    int $y
) : int
参数:
名称 说明
x x轴坐标
y y轴坐标

colorClosest()

取得与指定的颜色最接近的颜色索引

public function colorClosest (
    int $red,
    int $green,
    int $blue
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]

colorClosestAlpha()

取得与指定的颜色加透明度最接近的颜色索引

public function colorClosestAlpha (
    int $red,
    int $green,
    int $blue,
    int $alpha
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]
alpha 透明度[0 ~ 127]

colorClosestHwb()

取得与给定颜色最接近的色度的黑白色的索引

public function colorClosestHwb (
    int $red,
    int $green,
    int $blue
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]

colorDeallocate()

取消图像颜色分配

public function colorDeallocate (
    int $color
) : bool
参数:
名称 说明
color 颜色索引

colorExact()

取得指定颜色的索引值

public function colorExact (
    int $red,
    int $green,
    int $blue
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]
返回值:

如果颜色不在图像的调色板中,返回-1

colorExactAlpha()

取得指定的颜色加透明度的索引值

public function colorExactAlpha (
    int $red,
    int $green,
    int $blue,
    int $alpha
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]
alpha 透明度[0 ~ 127]
返回值:

如果颜色不在图像的调色板中,返回-1

colorMatch()

使一个图像中调色板版本的颜色与真彩色版本更能匹配

public function colorMatch (
    resource $image2
) : bool
参数:
名称 说明
image2 必须是调色板图像,而且和 image1 的大小必须相同

colorResolve()

取得指定颜色的索引值或有可能得到的最接近的替代值

public function colorResolve (
    int $red,
    int $green,
    int $blue
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]

colorResolveAlpha()

取得指定颜色 + alpha 的索引值或有可能得到的最接近的替代值

public function colorResolveAlpha (
    int $red,
    int $green,
    int $blue,
    int $alpha
) : int
参数:
名称 说明
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]
alpha 透明度[0 ~ 127]

colorSet()

给指定调色板索引设定颜色

public function colorSet (
    int $index,
    int $red,
    int $green,
    int $blue,
    int $alpha = 0
)
参数:
名称 说明
index 索引
red RGB成分[红]
green RGB成分[绿]
blue RGB成分[蓝]
alpha 透明度[0 ~ 127]

colorsForIndex()

取得颜色索引的信息

public function colorsForIndex (
    int $index
) : array
参数:
名称 说明
index 索引
返回值:

具有 red,green,blue 和 alpha 的键名的关联数组

colorStotal()

取得一幅图像的调色板中颜色的数目

public function colorStotal () : int

colorTransparent()

将某个颜色定义为透明色

public function colorTransparent (
    int $color = null
) : int
参数:
名称 说明
color 颜色索引
返回值:

返回新透明色的标识符

convolution()

用系数 div 和 offset 申请一个 3x3 的卷积矩阵

public function convolution (
    array $matrix,
    float $div,
    float $offset
) : bool
参数:
名称 说明
matrix 矩阵
div 卷积结果的除数
offset 颜色偏移
返回值:

成功时返回 TRUE, 或者在失败时返回 FALSE。

copy()

拷贝图像的一部分

public function copy (
    mixed $src_im,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $src_w,
    int $src_h
) : bool
参数:
名称 说明
src_im 要拷贝图像的资源对象或者图像文件路径
dst_x 目标开始坐标x轴
dst_y 目标开始坐标y轴
src_x 拷贝开始坐标x轴
src_y 拷贝开始坐标y轴
src_w 拷贝宽度
src_h 拷贝高度
返回值:

成功时返回 TRUE, 或者在失败时返回 FALSE。

copyMerge()

拷贝并合并图像的一部分

public function copyMerge (
    mixed $src_im,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $src_w,
    int $src_h,
    int $pct
) : bool
参数:
名称 说明
src_im 要拷贝图像的资源对象或者图像文件路径
dst_x 目标开始坐标x轴
dst_y 目标开始坐标y轴
src_x 拷贝开始坐标x轴
src_y 拷贝开始坐标y轴
src_w 拷贝宽度
src_h 拷贝高度
pct 合并程度,0-100

copyMergeGray()

用灰度拷贝并合并图像的一部分

public function copyMergeGray (
    mixed $src_im,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $src_w,
    int $src_h,
    int $pct
) : bool
参数:
名称 说明
src_im 要拷贝图像的资源对象或者图像文件路径
dst_x 目标开始坐标x轴
dst_y 目标开始坐标y轴
src_x 拷贝开始坐标x轴
src_y 拷贝开始坐标y轴
src_w 拷贝宽度
src_h 拷贝高度
pct 合并程度,0-100

copyResampled()

重采样拷贝部分图像并调整大小

public function copyResampled (
    mixed $src_im,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $dst_w,
    int $dst_h,
    int $src_w,
    int $src_h
) : bool
参数:
名称 说明
src_im 要拷贝图像的资源对象或者图像文件路径
dst_x 目标开始坐标x轴
dst_y 目标开始坐标y轴
src_x 拷贝开始坐标x轴
src_y 拷贝开始坐标y轴
dst_w 目标宽度
dst_h 目标高度
src_w 源宽度
src_h 源高度

copyResized()

拷贝部分图像并调整大小

public function copyResized (
    mixed $src_im,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $dst_w,
    int $dst_h,
    int $src_w,
    int $src_h
) : bool
参数:
名称 说明
src_im 要拷贝图像的资源对象或者图像文件路径
dst_x 目标开始坐标x轴
dst_y 目标开始坐标y轴
src_x 拷贝开始坐标x轴
src_y 拷贝开始坐标y轴
dst_w 目标宽度
dst_h 目标高度
src_w 源宽度
src_h 源高度

create()

新建一个基于调色板的图像

public function create (
    int $width,
    int $height,
    bool $truecolor = true
) : resource
参数:
名称 说明
width
height
truecolor 是否真彩色
返回值:

失败时返回false

createFrom()

从指定资源创建

public function createFrom (
    string $filename,
    string $from = null,
    array $options = []
) : resource
参数:
名称 说明
filename 文件路径
from 指定资源类型,不指定则自动检测
options 其他选项,目前仅对gd2part有效
返回值:

失败时返回false

crop()

裁剪图像

public function crop (
    array $rect
) : resource
参数:
名称 说明
rect 裁剪区域
返回值:

失败时返回false

参数 `$rect` :
[x, y, width, height]

cropAuto()

使用其中一种可用模式自动裁剪图像

public function cropAuto (
    int $mode = -1,
    float $threshold = 0.5,
    int $color = -1
) : resource
参数:
名称 说明
mode IMG_CROP_*敞亮
threshold 容忍度,以百分比为单位
color 颜色标识

dashedLine()

画一虚线

public function dashedLine (
    int $x1,
    int $y1,
    int $x2,
    int $y2,
    int $color
) : bool
参数:
名称 说明
x1 开始坐标x轴
y1 开始坐标y轴
x2 结束坐标x轴
y2 结束坐标y轴
color 颜色标识

destroy()

销毁一图像

public function destroy (
    resource $image
) : bool
参数:
名称 说明
image 图像资源

ellipse()

画一个椭圆

public function ellipse (
    int $cx,
    int $cy,
    int $width,
    int $height,
    int $color
) : bool
参数:
名称 说明
cx 中间的 X 坐标
cy 中间的 Y 坐标
width 宽度
height 高度
color 颜色标识

fill()

区域填充,即与 x, y 点颜色相同且相邻的点都会被填充

public function fill (
    int $x,
    int $y,
    int $color
) : bool
参数:
名称 说明
x X坐标
y Y坐标
color 颜色标识

filledArc()

画一椭圆弧且填充

public function filledArc (
    int $cx,
    int $cy,
    int $width,
    int $height,
    int $start,
    int $end,
    int $color,
    int $style
) : bool
参数:

filledEllipse()

画一椭圆并填充

public function filledEllipse (
    int $cx,
    int $cy,
    int $width,
    int $height,
    int $color
) : bool
参数:
名称 说明
cx 中心点x轴
cy 中心点y轴
width 宽度
height 高度
color 颜色标识

filledPolygon()

画一多边形并填充

public function filledPolygon (
    array $points,
    int $num_points,
    int $color
) : bool
参数:
名称 说明
points 顶点数组
num_points 顶点的总数,必须大于3
color 颜色标识
参数 `$points` :
按顺序包含有多边形各顶点的 x  y 坐标的数组

filledRectangle()

画一矩形并填充

public function filledRectangle (
    int $x1,
    int $y1,
    int $x2,
    int $y2,
    int $color
) : bool
参数:
名称 说明
x1 左上角x轴
y1 左上角y轴
x2 右下角x轴
y2 右下角y轴
color 颜色标识

fillToBorder()

区域填充到指定颜色的边界为止

public function fillToBorder (
    int $x,
    int $y,
    int $border,
    int $color
) : bool
参数:
名称 说明
x 开始点x轴
y 开始点y轴
border 边界颜色标识
color 填充颜色标识

filter()

使用过滤器

public function filter (
    int $filtertype,
    int $arg1 = null,
    int $arg2 = null,
    int $arg3 = null,
    int $arg4 = null
) : bool
参数:
名称 说明
filtertype 常量IMG_FILTER_*
arg1 可选参数1
arg2 可选参数2
arg3 可选参数3
arg4 可选参数4

flip()

使用给定模式翻转图像

public function flip (
    int $mode
) : bool
参数:
名称 说明
mode 常量IMG_FLIP_*

fontHeight()

取得字体高度

public static function fontHeight (
    int $font
) : int
参数:
名称 说明
font 字体标识

fontWidth()

取得字体宽度

public static function fontWidth (
    int $font
) : int
参数:
名称 说明
font 字体标识

ftbbox()

给出一个使用 FreeType 2 字体的文本框

public static function ftbbox (
    float $size,
    float $angle,
    string $fontfile,
    string $text,
    array $extrainfo = null
) : array
参数:
名称 说明
size 字体的尺寸
angle 使文本具有保密性的角度。
fontfile 字体文件路径
text 要渲染的字符串
extrainfo 其他设置
返回值:

数组含8个元素,失败时返回false

fttext()

使用 FreeType 2 字体将文本写入图像

public function fttext (
    float $size,
    float $angle,
    int $x,
    int $y,
    int $color,
    string $fontfile,
    string $text,
    array $extrainfo = null
) : array
参数:
名称 说明
size 字体的尺寸
angle 使文本具有保密性的角度。
x 左上角x轴
y 左上角y轴
color 颜色标识
fontfile 字体文件路径
text 要渲染的字符串
extrainfo 其他设置
返回值:

数组含8个元素,失败时返回false

gammaCorrect()

对 GD 图像应用 gamma 修正

public function gammaCorrect (
    float $inputgamma,
    float $outputgamma
) : bool
参数:
名称 说明
inputgamma 输入gamma
outputgamma 输出gamma

getClip()

取得剪切矩形

public function getClip () : array
返回值:4个元素

grabScreen()

捕捉整个屏幕

public static function grabScreen () : resource

grabWindow()

捕捉指定窗口

public static function grabWindow (
    int $window_handle,
    int $client_area = 0
) : resource
参数:
名称 说明
window_handle 句柄ID
client_area 包括应用程序窗口的客户端区域。

interlace()

激活或禁止隔行扫描

public function interlace (
    int $interlace = null
) : int
参数:
名称 说明
interlace 1激活,0禁止
返回值:

返回当前状态

isTrueColor()

检查图像是否为真彩色图像

public function isTrueColor () : bool

layerEffect()

设定 alpha 混色标志以使用绑定的 libgd 分层效果

public function layerEffect (
    int $effect
) : bool
参数:
名称 说明
effect 常量IMG_EFFECT_*

line()

画一条线段

public function line (
    int $x1,
    int $y1,
    int $x2,
    int $y2,
    int $color
) : bool
参数:
名称 说明
x1 起点x轴
y1 起点y轴
x2 终点x轴
y2 终点y轴
color 颜色标识

loadFont()

载入新字体

public static function loadFont (
    string $file
) : int
参数:
名称 说明
file 字体文件路径
返回值:

返回字体标识

openPolygon()

绘制一个开放多边形

public function openPolygon (
    array $points,
    int $num_points,
    int $color
) : bool
参数:
名称 说明
points 顶点数组
num_points 顶点数量
color 颜色标识

paletteCopy()

将调色板从一幅图像拷贝到另一幅

public function paletteCopy (
    resource $destination
)
参数:
名称 说明
destination 接收方图像资源

paletteToTrueColor()

将基于调色板的图像转换为真颜色

public function paletteToTrueColor () : bool

polygon()

画一个多边形

public function polygon (
    array $points,
    int $num_points,
    int $color
) : bool
参数:
名称 说明
points 顶点数组
num_points 顶点数量
color 颜色标识

psbbox()

给出一个使用 PostScript Type1 字体的文本方框

public static function psbbox (
    string $text,
    resource $font,
    int $size
) : array
参数:
名称 说明
text 要写入的文本
font 字体标识
size 字体大小

psEncodeFont()

改变字体中的字符编码矢量

public static function psEncodeFont (
    resource $font_index,
    string $encodingfile
) : bool
参数:
名称 说明
font_index 字体标识
encodingfile IsoLatin1.enc and IsoLatin2.enc.

psExtendFont()

扩充或精简字体

public static function psExtendFont (
    resource $font_index,
    float $extend
) : bool
参数:
名称 说明
font_index 字体标识
extend 扩展的值,必须大于 0。小于1则是精简该字体

psFreeFont()

释放一个 PostScript Type 1 字体所占用的内存

public static function psFreeFont (
    resource $font_index
) : bool
参数:
名称 说明
font_index 字体标识

psLoadFont()

从文件中加载一个 PostScript Type 1 字体

public static function psLoadFont (
    string $filename
) : resource
参数:
名称 说明
filename 字体文件路径
返回值:

失败时返回false

psSlantFont()

倾斜某字体

public static function psSlantFont (
    resource $font_index,
    float $slant
) : bool
参数:
名称 说明
font_index 字体标识
slant 倾斜度

psText()

用 PostScript Type1 字体把文本字符串画在图像上

public function psText (
    string $text,
    resource $font_index,
    int $size,
    int $foreground,
    int $background,
    int $x,
    int $y,
    int $space = 0,
    int $tightness = 0,
    float $angle = 0,
    int $antialias_steps = 4
) : array
参数:
名称 说明
text 要写入的文本
font_index 字体标识
size 字体大小
foreground 写入的字体的颜色标识
background 背景颜色标识
x 左下角起点x轴
y 左下角起点y轴
space 字体间距
tightness 字符间距
angle 角度
antialias_steps 可以控制防混色文本使用的颜色的数目
返回值:

有4个元素,失败返回false

rectangle()

画一个矩形

public function rectangle (
    int $x1,
    int $y1,
    int $x2,
    int $y2,
    int $color
) : bool
参数:
名称 说明
x1 左上角坐标x轴
y1 左上角坐标y轴
x2 右下角坐标x轴
y2 右下角坐标y轴
color 颜色标识

resolution()

获取或设置图像的分辨率

public function resolution (
    int $res_x = null,
    int $res_y = null
) : mixed
参数:
名称 说明
res_x 横向分辨率
res_y 纵向分辨率
返回值:

获取时返回数组[x,y],设置时返回结果

rotate()

用给定角度旋转图像

public function rotate (
    float $angle,
    int $bgd_color,
    int $ignore_transparent = 0
) : resource
参数:
名称 说明
angle 角度
bgd_color 指定旋转后未覆盖区域的颜色
ignore_transparent 如果被设为非零值,则透明色会被忽略(否则会被保留)。

saveAlpha()

设置标记以在保存 PNG 图像时保存完整的 alpha 通道信息(与单一透明色相反)

public function saveAlpha (
    bool $saveflag
) : bool
参数:
名称 说明
saveflag 是否保存透明(alpha)通道。默认 FALSE。

scale()

使用给定的新宽度和高度缩放图像

public function scale (
    int $new_width,
    int $new_height = -1,
    int $mode = 3
) : resource
参数:
名称 说明
new_width 新宽度
new_height 新高度,-1表示自动计算
mode 模式

setBrush()

设定画线用的画笔图像

public function setBrush (
    resource $brush
) : bool
参数:
名称 说明
brush 画笔图像

setClip()

设置剪切矩形

public function setClip (
    int $x1,
    int $y1,
    int $x2,
    int $y2
) : bool
参数:
名称 说明
x1 左上角坐标x轴
y1 左上角坐标y轴
x2 右下角坐标x轴
y2 右下角坐标y轴

setInterpolation()

设置插值方法

public function setInterpolation (
    int $method = 3
) : bool
参数:
名称 说明
method 方法常量

setPixel()

画一个单一像素

public function setPixel (
    int $x,
    int $y,
    int $color
) : bool
参数:
名称 说明
x 坐标x轴
y 坐标y轴
color 颜色标识

setStyle()

设定画线的风格

public function setStyle (
    array $style
) : bool
参数:
名称 说明
style 像素组成的数组

setThickness()

设定画线的宽度

public function setThickness (
    int $thickness
) : bool
参数:
名称 说明
thickness 宽度像素

setTile()

设定用于填充的贴图

public function setTile (
    resource $tile
) : bool
参数:
名称 说明
tile 贴图

stringHorizontal()

水平地画一行字符串

public function stringHorizontal (
    int $font,
    int $x,
    int $y,
    string $string,
    int $color
) : bool
参数:
名称 说明
font 字体标识
x 左上角坐标x轴
y 左上角坐标y轴
string 字符串
color 颜色标识

stringUp()

垂直地画一行字符串

public function stringUp (
    int $font,
    int $x,
    int $y,
    string $string,
    int $color
) : bool
参数:
名称 说明
font 字体标识
x 左上角坐标x轴
y 左上角坐标y轴
string 字符串
color 颜色标识

sx()

取得图像宽度

public function sx () : int

sy()

取得图像高度

public function sy () : int

trueColorToPalette()

将真彩色图像转换为调色板图像

public function trueColorToPalette (
    bool $dither,
    int $ncolors
) : bool
参数:
名称 说明
dither 指明图像是否被抖动
ncolors 设定调色板中被保留的颜色的最大数目

ttfbbox()

取得使用 TrueType 字体的文本的范围

public static function ttfbbox (
    float $size,
    float $angle,
    string $fontfile,
    string $text
) : array
参数:
名称 说明
size 像素单位的字体大小
angle 将被度量的角度大小
fontfile 字体文件路径
text 要度量的字符串
返回值:

8个元素,失败时返回false

ttftext()

用 TrueType 字体向图像写入文本

public function ttftext (
    float $size,
    float $angle,
    int $x,
    int $y,
    int $color,
    string $fontfile,
    string $text
) : array
参数:
名称 说明
size 像素单位的字体大小
angle 将被度量的角度大小
x 左上角坐标x轴
y 左上角坐标y轴
color 颜色标识
fontfile 字体文件路径
text 要写入的文本
返回值:

失败时返回false

types()

返回当前 PHP 版本所支持的图像类型

public static function types () : int
返回值:以比特字段方式返回

iptcEmbed()

将二进制 IPTC 数据嵌入到一幅 JPEG 图像中

public function iptcEmbed (
    string $iptcdata,
    int $spool = 0
) : mixed
参数:
名称 说明
iptcdata IPTC数据
spool 标识

iptcParse()

将二进制 IPTC 块解析为单个标记

public static function iptcParse (
    string $iptcblock
) : array
参数:
名称 说明
iptcblock IPTC块
返回值:

失败时返回false

jpeg2Wbmp()

将 JPEG 图像文件转换为 WBMP 图像文件

public static function jpeg2Wbmp (
     $jpegname,
     $wbmpname,
     $dest_height,
     $dest_width,
     $threshold
) : bool
参数:
名称 说明
jpegname  
wbmpname  
dest_height  
dest_width  
threshold  

png2Wbmp()

将 PNG 图像文件转换为 WBMP 图像文件

public static function png2Wbmp (
     $pngname,
     $wbmpname,
     $dest_height,
     $dest_width,
     $threshold
) : bool
参数:
名称 说明
pngname  
wbmpname  
dest_height  
dest_width  
threshold