Constants

THUMB_SCALING

THUMB_SCALING = 1

THUMB_FILLED

THUMB_FILLED = 2

THUMB_CENTER

THUMB_CENTER = 3

THUMB_NORTHWEST

THUMB_NORTHWEST = 4

THUMB_SOUTHEAST

THUMB_SOUTHEAST = 5

THUMB_FIXED

THUMB_FIXED = 6

WATER_NORTHWEST

WATER_NORTHWEST = 1

WATER_NORTH

WATER_NORTH = 2

WATER_NORTHEAST

WATER_NORTHEAST = 3

WATER_WEST

WATER_WEST = 4

WATER_CENTER

WATER_CENTER = 5

WATER_EAST

WATER_EAST = 6

WATER_SOUTHWEST

WATER_SOUTHWEST = 7

WATER_SOUTH

WATER_SOUTH = 8

WATER_SOUTHEAST

WATER_SOUTHEAST = 9

FLIP_X

FLIP_X = 1

FLIP_Y

FLIP_Y = 2

Properties

$im

$im : resource

图像资源对象

Type

resource

$gif

$gif : \think\image\gif\Gif

Type

Gif

$info

$info : array

图像信息,包括 width, height, type, mime, size

Type

array

Methods

open()

open(\SplFileInfo|string  $file) : \think\Image

打开一个图片文件

Parameters

\SplFileInfo|string $file

Returns

\think\Image —

save()

save(string  $pathname, null|string  $type = null, int  $quality = 80, bool  $interlace = true) : $this

保存图像

Parameters

string $pathname

图像保存路径名称

null|string $type

图像类型

int $quality

图像质量

bool $interlace

是否对JPEG类型图像设置隔行扫描

Returns

$this —

width()

width() : int

返回图像宽度

Returns

int —

图像宽度

height()

height() : int

返回图像高度

Returns

int —

图像高度

type()

type() : string

返回图像类型

Returns

string —

图像类型

mime()

mime() : string

返回图像MIME类型

Returns

string —

图像MIME类型

size()

size() : array

返回图像尺寸数组 0 - 图像宽度,1 - 图像高度

Returns

array —

图像尺寸

rotate()

rotate(int  $degrees = 90) : $this

旋转图像

Parameters

int $degrees

顺时针旋转的度数

Returns

$this —

flip()

flip(int  $direction = self::FLIP_X) : $this

翻转图像

Parameters

int $direction

翻转轴,X或者Y

Returns

$this —

crop()

crop(int  $w, int  $h, int  $x, int  $y, int  $width = null, int  $height = null) : $this

裁剪图像

Parameters

int $w

裁剪区域宽度

int $h

裁剪区域高度

int $x

裁剪区域x坐标

int $y

裁剪区域y坐标

int $width

图像保存宽度

int $height

图像保存高度

Returns

$this —

thumb()

thumb(int  $width, int  $height, int  $type = self::THUMB_SCALING) : $this

生成缩略图

Parameters

int $width

缩略图最大宽度

int $height

缩略图最大高度

int $type

缩略图裁剪类型

Returns

$this —

water()

water(string  $source, int  $locate = self::WATER_SOUTHEAST, int  $alpha = 100) : $this

添加水印

Parameters

string $source

水印图片路径

int $locate

水印位置

int $alpha

透明度

Returns

$this —

text()

text(string  $text, string  $font, int  $size, string  $color = '#00000000', int  $locate = self::WATER_SOUTHEAST, int  $offset, int  $angle) : $this

图像添加文字

Parameters

string $text

添加的文字

string $font

字体路径

int $size

字号

string $color

文字颜色

int $locate

文字写入位置

int $offset

文字相对当前位置的偏移量

int $angle

文字倾斜角度

Throws

\think\image\Exception

Returns

$this —

__destruct()

__destruct() : mixed

析构方法,用于销毁图像资源

Returns

mixed —

__construct()

__construct(\SplFileInfo  $file) : mixed

Parameters

\SplFileInfo $file

Returns

mixed —

gifNext()

gifNext() : mixed

切换到GIF的下一帧并保存当前帧

Returns

mixed —