php实现九宫格连线,php通过Grafika实现九宫格组图

什么是Grafika?

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

独特的功能

智能裁剪

动画GIF支持

5种缩略图模式

图像比较

图像高级过滤功能

图像混合

规范化的API

安装

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

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的部分居中剪裁掉,图片不会变形

$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');

}

最后生成一张合成图:

87837ec2506a7092773a5bac0e4558fc.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值