网站建设与管理的未来规划,成都模板网站建设服务,赣州微网站建设费用,网站建设价表模板我最近没有摸鱼#xff0c;一直都在工作。只不过目前需要爬一点数据 python 做的#xff0c;之后看机会分享一下。忙着忙着老大说要生成海报#xff0c;有个活动要给每个用户来个分享图。想法PS 批处理#xff1f;脚本#xff1f; 能甩出去的活都甩出去#xff0c;机智如…我最近没有摸鱼一直都在工作。只不过目前需要爬一点数据 python 做的之后看机会分享一下。忙着忙着老大说要生成海报有个活动要给每个用户来个分享图。想法PS 批处理脚本 能甩出去的活都甩出去机智如我啊python 处理图像(PIL)。这么坑的想法当然不是我想的了。虽然我实现了写个页面调用之前生成长截图的服务。之前有个为了方便分享微信做了生成长截图的服务。写个新的页面用一下即可。我堂堂前端er怎么能一直用别的工具呢我的锤子呢ps处理这个方案经过我调研行不通。(也有可能是我菜)对于批量打码统一操作这类的还可以。对于需要对应名字之类的比较无力python老大说 python。py 使用 PIL 库 写起来还蛮简单的。py 使用这段时间以来就是感觉这个编码格式极其难受。有没有大佬解救我一下。根据不同的类型输出数据txt 使用字体输出到对应位置image 图片覆盖输出到对应位置。maskimg要注意针对 png 来使用qrcode 生成对应二维码通过上面的类型来增加我们代码的扩展性。代码# -*- coding: utf-8 -*-from PIL import Image, ImageDraw, ImageFontimport qrcodeimport time;import redef AddMoney(data):bg Image.new(RGBA, (data[width], data[height]))for item in data[list]:print(item)if item[type] qrcode:qr_pil_obj qrcode.make(item[url], border0).resize((item[width], item[height]), Image.ANTIALIAS)bg.paste(qr_pil_obj,(item[x],item[y]))elif item[type] image:extname re.search( r(jpg|png|jpeg)$, item[url]).group()# 加载图片img Image.open(item[url])# 缩放if (item[width]! and item[height] ! ):img.resize((item[width], item[height]), Image.ANTIALIAS)if extname png:bg.paste(img,(item[x],item[y]), maskimg)else:bg.paste(img,(item[x],item[y]))elif item[type] text:draw ImageDraw.Draw(bg)ttfront ImageFont.truetype(item[ttfrontUrl],item[ttfrontSize])draw.text((item[x],item[y]),unicode(item[txt],UTF-8), fill(0,0,0), fontttfront)else:print(------------------------------)bg.save(data[outputName])data {width: 750,height: 1334,outputName: ./out-%s.png % (str(time.time())),list:[{type:image,url:./avatar.jpg,x:10,y:360,width:750,height:1334},{type:image,url:./bg.png,x:0,y:0,width:750,height:750},{type:qrcode,url:https://www.lilnong.top,x:0,y:0,width:120,height:120},{type:text,txt:你这个死宅说话,x:140,y:560,ttfrontUrl:./abc.ttf,ttfrontSize:55},{type:text,txt:还挺搞笑的,x:160,y:630,ttfrontUrl:./abc.ttf,ttfrontSize:55}]}AddMoney(data)长截图这个也是极好是之前一个 Node 的服务。省时省力。网上查也不少前端技术处理我堂堂前端怎么也得露一手吧。基于上面的页面已经成功。我们想一下我们需要干什么把 html 转成 canvas然后 canvas.toBlob,然后 download 美滋滋。html2canvas 这是一个库既然已经有写好的了我们就不费神了。(最难的一步。。。)拿到 cavnas 调用 API canvas.toBlob。微信公众号各种忘记发。补上补上结语py 写代码是真的短。前端处理需要注意跨域、URL空格等问题。作者linong