$item_pic = 'img/item.jpg';
$qcode_pic = 'img/qcode.png';
$user_pic = 'img/user.jpeg'; $item_title = "镇泰吹风机家用孕婴负离子护";
$item_title2 = "发蓝光大风力 家用";
$font_file = 'fonts/Microsoft_Yahei.ttf'; $item_price = '¥100.50'; $share_title = "来自邹喆的分享"; //创建画布
$percent = 0.5;
$width = 400;
$height = 700;
$image = imagecreatetruecolor($width, $height); //创建背景颜色
$image_bg = imagecolorallocate($image, 255, 255, 255);
//创建字体颜色
$image_text_bg = imagecolorallocate($image, 0, 0, 0); //创建价格颜色
$price_bg = imagecolorallocate($image, 255, 0, 0); //创建灰色颜色
$qcode_bg = imagecolorallocate($image, 128, 138, 135); //填充背景颜色
imagefill($image, 0, 0, $image_bg); //把商品图片合成到画布商品
//先把商品图片换成图片流
list($item_pic_width, $item_pic_height) = getimagesize($item_pic); $item_pic = imagecreatefromjpeg($item_pic); $new_item_width = $item_pic_width * $percent;
$new_item_height = $item_pic_height * $percent; //加入商品
imagecopyresized($image, $item_pic, 0, 120, 0, 0, $new_item_width, $new_item_height, $item_pic_width, $item_pic_height); //加入商品标题
imagettftext($image, 12, 0, 10, 590, $image_text_bg, $font_file, $item_title);
imagettftext($image, 12, 0, 11, 590, $image_text_bg, $font_file, $item_title); imagettftext($image, 12, 0, 25, 610, $image_text_bg, $font_file, $item_title2);
imagettftext($image, 12, 0, 26, 610, $image_text_bg, $font_file, $item_title2); //加入商品价格
imagettftext($image, 20, 0, 30, 650, $price_bg, $font_file, $item_price);
//加入推荐者头像 list($user_pic_width, $user_pic_height) = getimagesize($user_pic);
$user_pic = imagecreatefromjpeg($user_pic);
$new_user_pic_width = $user_pic_width * $percent;
$new_user_pic_height = $user_pic_height * $percent; imagecopyresampled($image, $user_pic, 80, 50, 0, 0, $new_user_pic_width, $new_user_pic_height, $user_pic_width, $user_pic_height);
//加入推荐者
imagettftext($image, 12, 0, 150, 100, $image_text_bg, $font_file, $share_title); //加入二维码
list($qcode_pic_width, $qcode_pic_height) = getimagesize($qcode_pic); $new_qcode_width = $qcode_pic_width;
$new_qcode_height = $qcode_pic_height; $qcode_pic = imagecreatefrompng($qcode_pic); imagecopyresized($image, $qcode_pic, 260, 550, 0, 0, $new_qcode_width, $new_qcode_height, $qcode_pic_width, $qcode_pic_height); //加入二维码文字
imagettftext($image, 10, 0, 277, 679, $qcode_bg, $font_file, '长按识别二维码');
header("Content-type:image/jpeg"); imagejpeg($image);
imagejpeg($image, 'img/0.jpg');

  效果图:

PHP GD库---之商详合成分享图片的更多相关文章

  1. GD库imagecopyresampled()方法详解~

    整理了一下GD库这个缩放,拉伸复制的方法 因为这个函数参数太多了~ imagecopyresampled()   /* //拷贝部分图像并调整大小 bool imagecopyresampled ( ...

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

    PHP 使用GD库合成带二维码的海报步骤以及源码实现 在做微信项目开发过程中,经常会遇到图片合成的问题,比如将用户的二维码合成到宣传海报中,那么,遇到这种情况,利用PHP的GD库也是很容易实现的,实现 ...

  3. 【PHP】使用GD库实现 图像生成、缩放、logo水印和简单验证码

    gd库是php最常用的图片处理库之一(另外一个是imagemagick),可以生成图片.验证码.水印.缩略图等等.要使用gd库首先需要开启gd库扩展, windows系统下需要在php.ini中将ex ...

  4. PHP 使用GD库合成带二维码和圆形头像的海报步骤以及源码实现

    PHP 使用GD库合成带二维码和圆形头像的海报步骤以及源码实现 之前记录过一篇文章,不过那只是简单将二维码合成到海报中去,这次还要合成头像,而且是圆形.所需要素材就不一一列举,直接代码吧 1.先获取用 ...

  5. PHP中GD库的使用

    1.基本步骤 <?php /** * Created by PhpStorm. * User: jiqing * Date: 18-4-9 * Time: 上午9:34 * 熟悉步骤 */ // ...

  6. PHP->利用GD库新建图像

    1.确认php中GD库是否开启 在PHP配置文件php.ini中查找extension=php_gd2.dll,去掉前边的(分号) ';' 即可,一般php是默认开启的 2.绘画步骤 创建一个画布(画 ...

  7. GD库使用小结---1

    因为一开始,“大家”都说一般任务中,用php操作图片不常见,像我们这种基本业务型的,就更用不到了,所以先别看,偶就没有看.现在有机会了自然要来玩一把. 以前学过C#的GDI+,交了课程设计后忘得一干二 ...

  8. PHP5 GD库生成图形验证码(汉字)

    PHP5 GD库生成图形验证码且带有汉字的实例分享. 1,利用GD库函数生成图片,并在图片上写指定字符imagecreatetruecolor 新建一个真彩色图像imagecolorallocate ...

  9. GD库 图片缩略图 图片水印

    /** * GD库 图片缩略图 *//*$image = imagecreatefromjpeg("1.jpg");var_dump($image);exit;$width = i ...

随机推荐

  1. 机器学习框架ML.NET学习笔记【9】自动学习

    一.概述 本篇我们首先通过回归算法实现一个葡萄酒品质预测的程序,然后通过AutoML的方法再重新实现,通过对比两种实现方式来学习AutoML的应用. 首先数据集来自于竞赛网站kaggle.com的UC ...

  2. java wait(),notify(),notifyAll()

    wait()的作用是使当前执行代码的线程进行等待,此方法是Object类的方法,该方法用来将当前线程置入“预执行队列”中,并且在wait()所带的代码处停止执行,直到接到通知或被中断位置.在调用wai ...

  3. ruby 数组 Hash相互转换

    由[索引, 值, ...] 型的数组变为哈希表 ary = [1,"a", 2,"b", 3,"c"] p Hash[*ary] # =&g ...

  4. C#实现程序单例日志输出

    对于一个完整的程序系统,一个日志记录是必不可少的.可以用它来记录程序在运行过程中的运行状态和报错信息.比如,那些不想通过弹框提示的错误,程序执行过程中捕获的异常等. 首先,在你的解决方案中,适当的目录 ...

  5. 09SpringAopAdvice

    Spring原生的经典模式 实现 AOP 通知: 前置通知:在目标方法执行之前执行,不能改变方法的执行流程和结果! 实现 MethodBeforeAdvice接口! 后置通知:在目标方法执行之后执行, ...

  6. (译)Minimal Shader(最小的着色器)

    (原文:https://en.wikibooks.org/wiki/Cg_Programming/Unity/Minimal_Shader) This tutorial covers the basi ...

  7. c# 字符串的首字母大写转换 方法

    方法1: s.Substring(0,1).ToUpper()+s.Substring(1);  方法2: s = System.Threading.Thread.CurrentThread.Curr ...

  8. 数据库(数据库、表及表数据、SQL语句)

    数据库MYSQL 今日内容介绍 u MySQL数据库 u SQL语句 第1章 数据库 1.1 数据库概述 l 什么是数据库 数据库就是存储数据的仓库,其本质是一个文件系统,数据按照特定的格式将数据存储 ...

  9. win10 vm 11 桥接模式配置

    1 保证你Vmware里面的虚拟机是关机状态 2 在本地连接 属性中 卸载VM 桥接协议 3 管理员身份运行VM ,编辑>虚拟网络编辑器 删除所有网卡,并且重新配置网络适配器 4 配置完成后,选 ...

  10. 有关mybatis的动态sql

    一般地,实现动态SQL都是在xml中使用等标签实现的. 我们在这里使用SQL构造器的方式, 即由abstract sql写出sql的过程, 当然感觉本质上还是一个StringBuilder, 来手动生 ...