加入收藏 | 设为首页 | 会员中心 | 我要投稿 成都站长网 (https://www.028zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php通过Grafika实现九宫格组图

发布时间:2023-01-11 15:31:29 所属栏目:PHP教程 来源:互联网
导读: 什么是Grafika?
Grafika是一个PHP图像处理库,功能强大。
独特的功能
安装
Grafika的官网
在项目根目录中,在命令行中输入:
composer require kosinix/grafika:dev-master --prefer-dist

什么是Grafika?

Grafika是一个PHP图像处理库,功能强大。

独特的功能

安装

Grafika的官网

在项目根目录中,在命令行中输入:

composer require kosinix/grafika:dev-master --prefer-dist

创建编辑器

编辑器用于操纵图像。推荐的方法是使用Grafika :: createEditor()。它会自动选择最佳编辑器。它将检查Imagick是否可用。如果没有,它将回归使用GD。

use Grafika\Grafika; // 引入包
$editor = Grafika::createEditor(); // 创建编辑器

编辑器包含所有的图片处理方法。

下面是我生成合成图的实际代码:

public function images()

{

try {

$editor = Grafika::createEditor();

$imageBack = Grafika::createBlankImage(750, 750);//创建一个750*750的空白图像

$image1 = $image2 = $image3= $image4 = '';

$editor->open($image1, 'E:/goodsPic/1.jpeg');//打开1.jpeg并且存放到$image1

$editor->resizeFill($image1, 375, 375);//居中剪裁。就是把较短的变缩放到200px,然后将长边的大于200px的部分居中剪裁掉PHP高级过滤器,图片不会变形

$editor->blend($imageBack, $image1, 'normal', 1, 'top-left');//将两个图像合成在一起,第一个图像作为基础,第二个图像在顶部。支持多种混合模式

$editor->save($imageBack, 'E:/goodsPic/all.jpg');//imageBack保存为all.jpg

$editor->open($image2, 'E:/goodsPic/2.jpg');

$editor->resizeFill($image2, 375, 375);

$editor->blend($imageBack, $image2, 'normal', 1, 'top-right');

$editor->save($imageBack, 'E:/goodsPic/all.jpg');

$editor->open($image3, 'E:/goodsPic/3.jpg');

$editor->resizeFill($image3, 375, 375);

$editor->blend($imageBack, $image3, 'normal', 1, 'bottom-left');

$editor->save($imageBack, 'E:/goodsPic/all.jpg');

$editor->open($image4, 'E:/goodsPic/4.jpg');

$editor->resizeFill($image4, 375, 375);

$editor->blend($imageBack, $image4, 'normal', 1, 'bottom-right');

$editor->save($imageBack, 'E:/goodsPic/all.jpg');

} catch (Exception $e){

echo $e->getMessage();

}

exit('run over');

}

最后生成一张合成图:

PHP高级过滤器_过滤式自救器主要过滤什么气体_过滤式自救器过滤什么气体



(编辑:成都站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!