boa框架开发手册v5.2

image类
版本 1.0+
命名空间 boa
文件 boa/image.php
说明 图像处理类,配置:'IMAGE' => [],
配置
配置项 默认值 类型 说明
driver gd string 图像驱动;可选值:gd, imagick
wm_type 2 int 水印类型;0=关闭 1=文字 2=图片
wm_ratio 0.4 int 水印与图像大小比例大于该值则不添加水印
wm_margin 5 int 当水印靠边时边距(像素)
wm_text boasoft.top string 水印文字
wm_font font.ttf string 水印字体,位于 BS_VAR .'image/'
wm_size 13 int 水印文字大小
wm_color #CC0000 string 水印文字颜色
wm_logo watermark.png string 水印图片,位于 BS_VAR .'image/'
wm_alpha 65 int 水印图片透明度
wm_pos 0 int 水印位置:0=随机,
1=上左,2=上中,3=上右,
4=中左,5=居中,6=中右,
7=下左,8=下中,9=下右
tb_width 320 int 缩略图宽度,-1=自动
tb_height 200 int 缩略图高度,-1=自动,宽高不能同时为-1
目录
方法 说明
__construct() 初始化
open() 打开一个图像
watermark() 添加水印
thumbnail() 生成缩略图
scale() 图像缩放,宽高不能同时为-1
crop() 图像剪裁
rotate() 图像旋转
flatten() 背景填充
flip() 图像翻转
text() 图像上写文字
reorient() 图像拍摄角度矫正
exif() 获取图像EXIF信息
save() 保存图像
output() 输出图像
方法

__construct()

说明
初始化
参数 必须 默认值 类型 说明
$cfg [] array 配置数据

open()

说明
打开一个图像
参数 必须 默认值 类型 说明
$img Y string 图像文件绝对路径
返回值
返回$this(object)

watermark()

说明
添加水印
返回值
返回$this(object)

thumbnail()

说明
生成缩略图
返回值
返回$this(object)

scale()

说明
图像缩放,宽高不能同时为-1
参数 必须 默认值 类型 说明
$width Y int 目标宽度,-1=自动
$height -1 int 目标高度,-1=自动
返回值
返回$this(object)

crop()

说明
图像剪裁
参数 必须 默认值 类型 说明
$width Y int 剪裁宽度
$height Y int 剪裁高度
$x 0 int 剪裁起点X坐标
$y 0 int 剪裁起点Y坐标
返回值
返回$this(object)

rotate()

说明
图像旋转
参数 必须 默认值 类型 说明
$angle Y int 旋转角度
$bgcolor #FFFFFF string 旋转后背景填充色
返回值
返回$this(object)

flatten()

说明
背景填充
参数 必须 默认值 类型 说明
$bgcolor #FFFFFF string 背景填充色
返回值
返回$this(object)

flip()

说明
图像翻转
参数 必须 默认值 类型 说明
$mode 0 int 翻转模式
  • -1=水平翻转
  • 1=垂直翻转
  • 0=同时翻转
返回值
返回$this(object)

text()

说明
图像上写文字
参数 必须 默认值 类型 说明
$text Y string 文字
$cfg [] array 包含以下元素:
  • x:写入起点X坐标,默认 0
  • y:写入起点Y坐标,默认为文字大小
  • angle:文字排列角度,默认 0
  • color:文字颜色,默认取配置 wm_color
  • font:字体文件,默认取配置 wm_font
  • size:文字大小,默认取配置 wm_size
返回值
返回$this(object)

reorient()

说明
图像拍摄角度矫正
返回值
返回$this(object)

exif()

说明
获取图像EXIF信息
参数 必须 默认值 类型 说明
$key null string EXIF键
返回值
返回EXIF信息(array),如指定key则返回该项值(string)

save()

说明
保存图像
参数 必须 默认值 类型 说明
$to null string 保存路径,可为不同后缀,默认覆盖原图
$quality 90 int 图像质量
返回值
返回图像路径(string)

output()

说明
输出图像
参数 必须 默认值 类型 说明
$type null string 输出类型,可选值:png, jpeg, gif
返回值
返回$this(object)