分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

php通过Grafika实现九宫格组图

发布时间:2023-09-06 02:21责任编辑:顾先生关键词:九宫格

什么是Grafika?

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

独特的功能

  • 智能裁剪
  • 动画GIF支持
  • 5种缩略图模式
  • 图像比较
  • 图像高级过滤功能
  • 图像混合
  • 规范化的API

安装

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的部分居中剪裁掉,图片不会变形
???  $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通过Grafika实现九宫格组图

原文地址:https://www.cnblogs.com/designers/p/9922852.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved