$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. Spring连接数据库

    public class Book { private int bookid; private String bookname; private String bookauthor; private ...

  2. 如何使用markdown编辑器编写文章

    1 设置markdown编辑器为默认编辑器 进入我的博客,点击管理 点击选项,勾选markdown编辑器即可 2 markdown 语法 注意,文章中的# - 1. > 只有在段落开头且符号后需 ...

  3. 编写生成32位大写和小写字符的md5的函数

    package nicetime.com.practise; import java.security.MessageDigest; /** * MD5加密是JAVA应用中常见的算法,请写出两个MD5 ...

  4. How to restrict root user to access or modify a file and directory in Linux

    Now in this article I will show you steps to prevent or restrict access of root user to access certa ...

  5. linux必会命令-查询-tail

    先说一个tail使用的例子: tail -n 20 filename 说明:显示filename最后20行. Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最 ...

  6. java基础——冒泡排序

    最近开始准备面试,所以将Java基础复习一遍,又学习了冒泡排序 冒泡排序的基本思想是,对相邻的元素进行两两比较,顺序相反则进行交换,这样,每一趟会将最小或最大的元素“浮”到顶端,最终达到完全有序 ja ...

  7. shell脚本,awk取中间列的方法。

    解释 1.$(int(NF/2)+1) 中int(NF/2)等于3,然后加1,就得到中间的4了. 2.$(NF/2+0.5) 相当于得出的是整数.NF/2是3.5,再由3.5+0.5,所以就是4了,也 ...

  8. ORACLE的SQL JOIN方式大全

    ORACLE的SQL JOIN方式大全 在ORACLE数据库中,表与表之间的SQL JOIN方式有多种(不仅表与表,还可以表与视图.物化视图等联结),官方的解释如下所示 A join is a que ...

  9. 01_8_sql主键生成方式

    01_8_sql主键生成方式 1. 配置映射文件 <insert id="insertStudentBySequence" parameterClass="Stud ...

  10. js函数式编程(二)-柯里化

    这节开始讲的例子都使用简单的TS来写,尽量做到和es6差别不大,正文如下 我们在编程中必然需要用到一些变量存储数据,供今后其他地方调用.而函数式编程有一个要领就是最好不要依赖外部变量(当然允许通过参数 ...