Generate posters (front end | python)


I haven’t fished recently.Always working。 It’s just a little bit of data to crawl right now.pythonDo it, and then see the opportunity to share it.

Busy with the boss said to generate posters, there is an activity to give each user a share map.


  1. PS batch processing? Script?Everything that can be dumped out is dumped out.Wisdom is like mine
  2. Python processes images (PIL). Such pitfalls are certainly not what I thought.Although I realized it.
  3. Write a page to call a service that generates a long screenshot before calling it. There was a service that generated growth screenshots to facilitate the sharing of Wechat. Write a new page and use it.
  4. My front end erHow can you always use other tools? Where’s my hammer?

PS processing

This project, after my researchIt won’t work。 (Or maybe it’s my dish)
For batch coding, unified operation of this kind is also possible.
It’s weak for things like the need for a corresponding name.


The boss said PythonpyUsePILThe library is quite simple to write.
pyIt’s been feeling like this for a while.The encoding format is extremely uncomfortable。 Is there a big man to rescue me?

Output data according to different types

  1. Txt uses fonts and outputs them to corresponding locations
  2. Image image, covering the output to the corresponding location.mask=imgAttention should be paid to targetpngTo use
  3. Qrcode Generates Corresponding Two-Dimensional Codes

Increase the extensibility of our code through the above types.


# -*- coding: utf-8 -*-
from PIL import Image, ImageDraw, ImageFont
import qrcode
import time;
import re
def AddMoney(data):
  bg ='RGBA', (data['width'], data['height']))
  for item in data['list']:
    if item['type'] == 'qrcode':
      qr_pil_obj = qrcode.make(item['url'], border=0).resize((item['width'], item['height']), Image.ANTIALIAS)
    elif item['type'] == 'image':
      extname = r'(jpg|png|jpeg)$', item['url']).group()
      # Loading Pictures
      img =['url'])
      # Zoom
      if (item['width']!= '' and item['height'] != ''):
        img.resize((item['width'], item['height']), Image.ANTIALIAS)

      if extname == 'png':
        bg.paste(img,(item['x'],item['y']), mask=img)
    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), font=ttfront)

data = {
  'width': 750,
  'height': 1334,
  'outputName': './out-%s.png' % (str(time.time())),
  ''list': [{``type': [{````image', """""""url": ". / avatar.jpg"""""""""x""": 10,"y": 360,"width": width": 750, "height": 1334},{``````````type'''''{``````type''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''"Type", "text", "txt", "You talk in a dead house", "x": 140," "Y": 560, "ttfrontUrl":". / abc. ttf", "ttfrontSize": 55}, {type","text","txt":"funny","x": 160", "y": 630, "ttfrontUrl":. / abc. ttf","ttfrontSize": 55}]

Long screenshot

This is also excellent. It’s the previous one.NodeService. It saves time and effort. There are also many online searches.

Front-end technology processing

I have to show my hand in front of the hall.
Based on the above page has been successful. Let’s think about what we need to do. holdhtmlTurn intocanvasThencanvas.toBlobThendownloadMeizzizi.

  1. html2canvasThis is a library. Now that it has been written, we won’t bother. (The hardest step.)
  2. GetcavnascallAPIcanvas.toBlob
  3. Download. This is relatively simple. I have written about the front-end training – the initial stage – Scene Actual Warfare (2019-06-06) – download files – download progress before.

Wechat Public Number

All kinds of forgetting. Fill in
Generate posters (front end | python)


pyWriting code is really short.
Front-end processing needs attentionCross domainURL SpacesAnd so on.

Recommended Today

In 2021, what are the good ways to realize apps?

I believe many developers feel helpless when they see the word “cash”. The reason is that as app builders, they have spent a lot of effort in the construction of APP architecture, technology research and development, operation and maintenance, and realization is the decisive survival weight for them. Successful realization not only means the continuation […]