代码:

public function mergePic(){
$ground = '/Public/merge/beijing.png';
$img = [
'url'=>'/Public/merge/qrcode.png',
'x'=>100,
'y'=>100
];
$qr = [
'url'=>'/Public/merge/qr.jpg',
'x'=>150,
'y'=>1400
];
$text = [
'size'=>20,
'text'=>'123456'
];
$this->merge($ground,$img,$qr,$text);
} /**
* @param $ground string 背景
* @param $img array 图片
* @param $qr array 二维码
* @param $text array 文字
*/
public function merge($ground,$img=[],$qr=[],$text=[]){
$types = [
"image/jpg" => 'imagecreatefromjpeg',
"image/jpeg" => 'imagecreatefromjpeg',
"image/png" => 'imagecreatefrompng',
"image/pjpeg" => 'imagecreatefromjpeg',
"image/gif" => 'imagecreatefromgif',
"image/bmp" => 'imagecreatefromwbmp',
"image/x-png" => 'imagecreatefromjpeg'
];
$groundMime = getimagesize(getcwd().$ground);
$grounds = $types[$groundMime['mime']](getcwd().$ground);//获取图片资源
// $fileName = "/Public/merge/".time().".png";//保存图片目录
$fileName = "/Public/merge/123.png";//保存图片目录
if($img){
$imgMime = getimagesize(getcwd().$img['url']);
$imgs = $types[$imgMime['mime']](getcwd().$img['url']);//获取图片资源
$imgsW = imagesx($imgs);//图片宽
$imgsH = imagesy($imgs);//图片高
imagecopy($grounds, $imgs, $img['x'], $img['y'], 0, 0, $imgsW, $imgsH);//核心函数:复制图片资源到另一图片资源中
} if($qr){
$qrMime = getimagesize(getcwd().$qr['url']);
$qrs = $types[$qrMime['mime']](getcwd().$qr['url']);//获取图片资源
$qrsW = imagesx($qrs);//图片宽
$qrsH = imagesy($qrs);//图片高
imagecopy($grounds, $qrs, $qr['x'], $qr['y'], 0, 0, $qrsW, $qrsH);//核心函数:复制图片资源到另一图片资源中
} if($text){
$size = $text['size'];//字体大小
$font = "./Public/merge/yuanti.ttf";//字体
$text = $text['text'];//显示的文字
$grey = imagecolorallocate($grounds,0,0,0);//设置字体颜色
imagettftext($grounds,$size,0,100,100,$grey,$font,$text);//将ttf文字写到图片中
} imagepng($grounds,getcwd().$fileName); //保存
imagedestroy($grounds);
imagedestroy($imgs);
imagedestroy($qrs);//销毁图片资源
}

参考:

PHP 使用GD库合成带二维码的海报步骤以及源码实现

将图片绘制到画布上:imagecopy()

php合成图片 文字的更多相关文章

  1. [JavaScript] canvas 合成图片和文字

    Canvas Canvas 是 HTML5 新增的组件,就像一个画板,用 js 这杆笔,在上面乱涂乱画 创建一个 canvas <canvas id="stockGraph" ...

  2. PHP合成图片、生成文字、居中对齐、画线、矩形、三角形、多边形、图片抗锯齿、不失真 高性能源码示例

    function generateImg($source, $text1, $text2, $text3, $font = './msyhbd.ttf') { $date = '' . date ( ...

  3. PHP生成小程序二维码合成图片生成文字

    这部分代码是写在项目上的代码,THINKPHP3.1如果迁移到其他的地方应该要稍稍改动一下以适合自己的项目 function get_bbox($text,$fsize,$ffile){ return ...

  4. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 18—Photo OCR 应用实例:图片文字识别

    Lecture 18—Photo OCR 应用实例:图片文字识别 18.1 问题描述和流程图 Problem Description and Pipeline 图像文字识别需要如下步骤: 1.文字侦测 ...

  5. [C13] 应用实例:图片文字识别(Application Example: Photo OCR)

    应用实例:图片文字识别(Application Example: Photo OCR) 问题描述和流程图(Problem Description and Pipeline) 图像文字识别应用所作的事是 ...

  6. UIButton的titleEdgeInsets属性和imageEdgeInsets属性实现图片文字按要求排列

    button可以设置 titleEdgeInsets属性和 imageEdgeInsets属性来调整其image和label相对位置,具体参考http://stackoverflow.com/ques ...

  7. iOS UIButton 图片文字上下垂直布局 解决方案

    实现如图所示效果: 这是一个UIButton,需要改变image和title相对位置. 解决如下: //设置文字偏移:向下偏移图片高度+向左偏移图片宽度 (偏移量是根据[图片]大小来的,这点是关键)b ...

  8. 『方案』《女友十年精华》 ORC 图片 文字识别 详解

    目的需求: 2008年,遇到一本电子书 <女友十年精华> 觉得很美,想 私藏 这些文章: >网络搜索文章 —— 没有找到: >反编译程序 —— 所有文字 都是图片格式(部分文章 ...

  9. CSS 实现:图片+文字的布局(综合)

    ☊[实现要求]:图片+文字+居中 √[实现]: ① img + 文字 <div class="demo2-1"> <img src="" al ...

随机推荐

  1. The associated COM server does not support ActiveX Document embedding

    winfrom 通过dsoframer实现读取excel文件报错: System.Reflection.TargetInvocationException: Exception has been th ...

  2. Sys.WebForms.PageRequestManagerParserErrorException: 常见的原因是:通过调用Response.Write()修改相应时,将启用响应筛选器、HttpModules或服务器追踪

    Sys.WebForms.PageRequestManagerParserErrorException: 无法分析从服务器收到的消息,之所以出现此错误,常见的原因是:通过调用Response.Writ ...

  3. [翻译] SVProgressHUD

    SVProgressHUD https://github.com/TransitApp/SVProgressHUD SVProgressHUD is a clean and easy-to-use H ...

  4. Emacs快捷键(较全)

    C = Control M = Meta = Alt | Esc Del = Backspace 基本快捷键(Basic) C-x C-f "find"文件, 即在缓冲区打开/新建 ...

  5. C++显式隐式构造函数

    https://blog.csdn.net/starlee/article/details/1331268#comments

  6. 乘风破浪:LeetCode真题_008_String to Integer (atoi)

    乘风破浪:LeetCode真题_008_String to Integer (atoi) 一.前言 将整型转换成字符串,或者将字符串转换成整型,是经常出现的,也是必要的,因此我们需要熟练的掌握,当然也 ...

  7. docker 17.09.0-ce 启动更换网络地址

    一.环境准备 环境1 台虚拟机,系统为centos7 二.17.09.0-ce 安装 卸载安装的所有Docker组件 在 Docker17.03.0-ce 版本中,与在 Docker 1.12 中引入 ...

  8. requirejs 多页面,多js 打包代码,requirejs多对多打包

    这段代码来自 http://stackoverflow.com/questions/20583812/grunt-requirejs-optimizer-for-a-multi-app-project ...

  9. JavaScript(核心、BOM、DOM)

    http://www.flyne.org/article/407 JavaScript(核心.BOM.DOM) JavaScript是基于对象和事件驱动的客户端脚本语言.有如下特点: 交互性 安全性( ...

  10. 以整数元素构成的list中的数字组成最小整数

    问题 把一个int型数组中的数字拼成一个串,这个串代表的数字最小. 思路说明 不同角度,对原题理解有所不同.我依照以下的理解方式求解. 对这个问题的理解: 有一个元素是int类型的list: 将上述l ...