toropyga/fimages

用于处理Toropyga图像的库

v4.0.3 2021-08-10 17:01 UTC

This package is auto-updated.

Last update: 2024-09-11 11:18:48 UTC


README

图像处理类

内容

通用概念

FImages类用于编辑图像和生成验证码。要使用此类,需要PHP 5及以上版本,以及GD库。

FImages类的功能

FImages类允许编辑现有图像和传递的图像。

允许按比例或裁剪调整图像大小到指定参数。

创建使用原始图像填充的文件,并按指定比例拉伸。

在图像上添加文字。

旋转图像绕其轴旋转,并显示其镜像。

生成并显示验证码等。

示例

类的核心参数

$TYPE - create as
     $TYPE = 'GIF';
     $TYPE = 'JPEG'; //$TYPE = 'JPG';
     $TYPE = 'PNG';
     $TYPE = 'WEBP';

$path    - Path to image;
$dpath   - Path to save;
$name    - new image name;
$w       - end width;
$h       - end height;
$img     - string of image
$save    - end results (куда и как сохранить/вывести файл)
     $save = 1 // replace old image and return this file as string
     $save = 2 // print new image
     $save = 3 // return new file as string
     $save != 1 or 2 or 3 //return descriptor of new file;

使用方法

裁剪到指定参数的文件

include ("FImages.php");
$IMG = new FImages($TYPE, $w, $h);
$IMG->cut($path, $save);

裁剪到指定参数的文件,并以字符串形式返回

include ("FImages.php");
$IMG = new FImages($TYPE, $w, $h);
$image = $IMG->cut($path);

按指定比例拉伸的文件

include ("FImages.php");
$IMG = new FImages();
$IMG->resize($path, $save, $w, $h);

按比例调整大小的文件

include ("FImages.php");
$IMG = new FImages();
$IMG->resize_pro($path, $save, $w, $h); # proportion resize

使用原始图像填充的文件

$IMG->fill($path, $save, $w, $h); # fill background

从源创建临时文件并获取其数据

$IMG->getTempFile($img, $function, $save, $w, $h);

创建图像副本

include ("FImages.php");
$IMG = new FImages('JPG', 40, 40);
$ds = $IMG->resize($path);
$IMG->createImgCopy($ds, $dpath, $name);

生成验证码

<img src='".$IMG->captcha(false)."'> or $IMG->captcha();

返回验证码字符以进行检查

$IMG->getKeyString(); // captcha in string