Download the PHP package tp5er/images without Composer
On this page you can find all versions of the php package tp5er/images. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package images
参考thinkphp3.2.3中Image操作
https://www.kancloud.cn/manual/thinkphp/1878
不依赖任何框架
一般情况下都会安装gd库
需要Imagick请安装 https://pecl.php.net/package/imagick
实例化类库
$image = new \tp5er\Images\Image();
默认使用GD库进行图像操作,如果需要使用Imagick库操作的话,需要改成:
图像操作
下面来看下基础的图像操作功能的使用方法。
打开图像文件
假设当前入口文件目录下面有一个1.jpg文件
使用open方法打开图像文件进行相关操作:
也可以简化成下面的方式:
获取图像信息
可以获取打开图片的信息,包括图像大小、类型等,例如:
$width = $image->width(); // 返回图片的宽度
$height = $image->height(); // 返回图片的高度
$type = $image->type(); // 返回图片的类型
$mime = $image->mime(); // 返回图片的mime类型
$size = $image->size(); // 返回图片的尺寸数组 0 图片宽度 1 图片高度
裁剪图片
使用crop和save方法完成裁剪图片功能。
支持从某个坐标开始裁剪,例如下面从(100,30)开始裁剪:
生成缩略图
使用thumb方法生成缩略图
// 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
$image->thumb(150, 150)->save('./thumb.jpg');
可以支持其他类型的缩略图生成,设置包括\tp5er\Images\Image
的下列常量或者对应的数字:
IMAGE_THUMB_SCALE = 1 ; //等比例缩放类型
IMAGE_THUMB_FILLED = 2 ; //缩放后填充类型
IMAGE_THUMB_CENTER = 3 ; //居中裁剪类型
IMAGE_THUMB_NORTHWEST = 4 ; //左上角裁剪类型
IMAGE_THUMB_SOUTHEAST = 5 ; //右下角裁剪类型
IMAGE_THUMB_FIXED = 6 ; //固定尺寸缩放类型
居中裁剪
左上角剪裁
缩放填充
固定大小
添加图片水印
water方法的第二个参数表示水印的位置,可以传入下列Think\Imag类的常量或者对应的数字:
例如:
还可以支持水印图片的透明度(0~100,默认值是80),例如:
也可以支持给图片添加文字水印(假设在入口文件的同级目录下存在1.ttf字体文件),例如:
All versions of images with dependencies
PHP Build Version
Package Version
No informations.
The package tp5er/images contains the following files
Loading the files please wait ....