/**
* 二维码商品
* number origPrice 原价
* number price 券后价
* number couponPrice 优惠券金额
* string title 商品标题
* string picurl 商品图片网址
* string qrtext 二维码文字
* return string 生成的临时海报地址
**/
import gdip
import qrencode.bitmap
qrGoods = function(origPrice,price,couponPrice,title,picurl,qrtext){
import inet.whttp;
whttp = inet.whttp();
//白背景画布
var qrGoods = gdip.bitmap(750,1334)
var canvas = gdip.graphics(qrGoods).clear(0xFFFFFFFF)
//消除锯齿
canvas.smoothingMode = 4
//平滑处理
canvas.textRenderingHint = 3
//笔刷字体
var family = gdip.family("微软雅黑")
//绘制商品标题
canvas.drawString(title,family.createFont(32),::RECTF(60,80,633),,gdip.solidBrush(0xFF323232))
//下载并绘制商品图
var pic = gdip.image( whttp.get(picurl) )
canvas.drawImageRect(pic, 60, 215, 633, 833)
//绘制券后价
var cred = gdip.solidBrush(0xFFFD2624)
canvas.drawString("券后价",family.createFont(35),::RECTF(60,900),,cred)
canvas.drawString("¥",family.createFont(35,1),::RECTF(175,900),,cred)
canvas.drawString(tostring(price),family.createFont(50,1),::RECTF(210,885),,cred)
//绘制原价
var cgray = gdip.solidBrush(0xFF979797)
canvas.drawString("原价 ¥",family.createFont(25),::RECTF(60,970),,cgray)
canvas.drawString(tostring(origPrice),family.createFont(35,8),::RECTF(139,960),,cgray)
//绘制优惠券
var pic = gdip.image("\res\qrico.png")
canvas.drawImageRect(pic, 515, 880, 180, 70)
var cwhite = gdip.solidBrush(0xFFFFFFFF)
var x1 = 510
var x2 = 520
if(couponPrice <100){
x1 = 535
x2 = 555
}elseif(couponPrice <1000){
x1 = 520
x2 = 540
}
canvas.drawString("¥",family.createFont(25),::RECTF(x1,905),,cwhite)
canvas.drawString(tostring(couponPrice),family.createFont(50,1),::RECTF(x2,885),,cwhite)
//绘制二维码
var qr = qrencode.bitmap(qrtext,2,2).copyBitmap(170)
canvas.drawImageRect(qr, 515, 1075, 170, 170)
//绘制提示文字
canvas.drawString("新品生活-少花钱,多生钱",family.createFont(28),::RECTF(170,1140),,gdip.solidBrush(0xFF666666))
canvas.drawString("长按图片,扫码领取优惠券",family.createFont(23),::RECTF(210,1200),,cgray)
//保存
var tmp = "res/ad.jpg"
qrGoods.save(tmp, 90)
return tmp
}
import console;
import inet.http;
var ret = qrGoods(100,60,100,"美特斯邦威外套男装2018夏季新款轻薄多色个性百搭休闲连帽夹克","https://img.alicdn.com/imgextra/i1/134363478/TB2p_3gkr1YBuNjSszeXXablFXa-134363478.jpg","http://www.sina.com.cn")
console.log(ret)
console.pause()