$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. 将JWT与Spring Security OAuth结合使用

    1.概述 在本教程中,我们将讨论如何使用Spring Security OAuth2实现来使用JSON Web令牌. 我们还将继续构建此OAuth系列的上一篇文章. 2. Maven配置 首先,我们需 ...

  2. js中Object.defineProperty()和defineProperties()

    在介绍js中Object.defineProperty()和defineProperties()之前,我们了解下js中对象两种属性的类型:数据属性和访问器属性. 数据属性 数据属性包含一个数据的位置, ...

  3. JavaBean+jsp开发模式 --结合form表单 实例

    1.创建form表单 <%@ page language="java" contentType="text/html; charset=UTF-8" pa ...

  4. C# List的使用

    1.所需引入的命名空间: using System.Collections.Generic; 2.初始化 [1]空: List<int> list = new List<int> ...

  5. javascript对象的学习

    一.对象的定义: 对象是JavaScript的一个基本数据类型,是一种复合值,它将很多值(原始值或者其他对象)聚合在一起,可通过名字访问这些值.即属性的无序集合. JavaScript 提供多个内建对 ...

  6. C++ string 类型提取字符串

    在某些情况下需要对输入的字符串进行处理,提取其中的需要的信息. 比如在linux中输入"mkdir test",新建test文件夹,就需要提取其中的test字符. 提取的方法需要b ...

  7. jmeter的安装和基本使用

    本篇文章主要介绍一下JMeter的安装及基本使用方法. 1.安装 JMeter的官方网址为http://jmeter.apache.org/ 下载地址为http://jmeter.apache.org ...

  8. ADO.Net——增、删、改、查

    数据访问 对应命名空间:System.Data.SqlClient; SqlConnection:连接对象 SqlCommand:命令对象 SqlDataReader:读取器对象 CommandTex ...

  9. userBean-作用范围session

    package com.java1234.model; public class Student { private String name;private int age; public Strin ...

  10. 【UWP】【新坑】Excel批量翻译工具(1)

    嗯……具体思路是这样的.使用的时候,你导入一个excel,直观地选择某些区域,选择语言点击翻译,就可以对多个单元格进行批量翻译,并且支持多种不同的导出格式(excel副本.txt文件……) 1,多种翻 ...