图片工具类

属性
命名空间 fize\image
类名 Image
方法:
方法名 说明
affine() 仿射变换
crop() 裁剪图像
rotate() 用给定角度旋转图像
scale() 使用给定的新宽度和高度缩放图像
flip() 使用给定模式翻转图像
water() 添加图片水印
text() 添加文字水印

方法

affine()

仿射变换

public static function affine (
    string $file_name,
    array $affine,
    array $clip = null,
    string $to = null
) : bool
参数:
名称 说明
file_name 图像文件路径
affine [ a0, b0, a1, b1, a2, b2 ]
clip 剪切区域
to 保存路径,不指定时则覆盖原图片
返回值:

成功时返回true,失败时返回false

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

crop()

裁剪图像

public static function crop (
    string $file_name,
    array $rect,
    string $to = null
) : bool
参数:
名称 说明
file_name 图像文件路径
rect 裁剪区域
to 保存路径,不指定时则覆盖原图片
返回值:

成功时返回true,失败时返回false

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

rotate()

用给定角度旋转图像

public static function rotate (
    string $file_name,
    float $angle,
    int $bgd_color = 0,
    int $ignore_transparent = 0,
    string $to = null
) : bool
参数:
名称 说明
file_name 图像文件路径
angle 角度
bgd_color 指定旋转后未覆盖区域的颜色
ignore_transparent 如果被设为非零值,则透明色会被忽略。
to 保存路径,不指定时则覆盖原图片
返回值:

成功时返回true,失败时返回false

scale()

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

public static function scale (
    string $file_name,
    int $new_width,
    int $new_height = -1,
    int $mode = 3,
    string $to = null
) : bool
参数:
名称 说明
file_name 图像文件路径
new_width 新宽度
new_height 新高度,-1表示自动计算
mode 模式
to 保存路径,不指定时则覆盖原图片
返回值:

成功时返回true,失败时返回false

flip()

使用给定模式翻转图像

public static function flip (
    string $file_name,
    int $mode,
    string $to = null
) : bool
参数:
名称 说明
file_name 图像文件路径
mode 常量IMG_FLIP_*
to 保存路径,不指定时则覆盖原图片
返回值:

成功时返回true,失败时返回false

water()

添加图片水印

public static function water (
    string $file_name,
    string $source,
    array $coord,
    int $alpha = 100,
    string $to = null
) : bool
参数:
名称 说明
file_name 图像文件路径
source 水印文件路径
coord 水印坐标
alpha 透明度
to 保存路径,不指定时则覆盖原图片
参数 `$coord` :
支持键名[left、right、top、bottom]

text()

添加文字水印

public static function text (
    string $file_name,
    array $coord,
    string $text,
    string $font,
    int $size,
    string $color = "#00000000",
    int $angle = 0,
    string $to = null
) : bool
参数:
名称 说明
file_name 图像文件路径
coord 水印坐标
text 水印文字
font 字体文件路径
size 字体大小
color RGBA颜色值
angle 角度
to 保存路径,不指定时则覆盖原图片
参数 `$coord` :
支持键名[left、right、top、bottom]