php通过Grafika实现九宫格组图
Grafika是一个PHP图像处理库,功能强大。
独特的功能
安装
Grafika的官网
在项目根目录中,在命令行中输入:
composer require kosinix/grafika:dev-master --prefer-dist
什么是Grafika? Grafika是一个PHP图像处理库,功能强大。 独特的功能 安装
在项目根目录中,在命令行中输入:
创建编辑器 编辑器用于操纵图像。推荐的方法是使用Grafika :: createEditor()。它会自动选择最佳编辑器。它将检查Imagick是否可用。如果没有,它将回归使用GD。
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'); } 最后生成一张合成图: (编辑:成都站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |