-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcard.py
More file actions
634 lines (579 loc) · 23.4 KB
/
Copy pathcard.py
File metadata and controls
634 lines (579 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
# coding: utf-8
from datetime import datetime
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.http import HttpResponseServerError
from django.shortcuts import render
from django.urls import reverse
from django.views import View
from leancloud import Object
from leancloud import Query
from leancloud.errors import LeanCloudError
from PIL import Image, ImageColor, ImageFont, ImageDraw, ImageFilter
from io import BytesIO
from textwrap import *
import re
import leancloud
import urllib
import json
from qiniu import Auth, set_default, etag, PersistentFop, build_op, op_save, Zone
from qiniu import put_data, put_file, put_stream
from qiniu import BucketManager, build_batch_copy, build_batch_rename, build_batch_move, build_batch_stat, build_batch_delete
from qiniu import urlsafe_base64_encode, urlsafe_base64_decode
import os
from movie import Movie
import datetime
from weixin import weixin
class Card(Object):
pass
class Photo(Object):
pass
class User(Object):
pass
def template_send(card):
user = card.get('user')
openId = user.get('authData').get('lc_weapp').get('openid')
#lc_weapp = authData.get('lc_weapp')
#openId = lc_weapp.get('openid')
template_id = 'kiS8i4JzVR8mZ-gRnS1gaawCLa_dGe0zhy1JFnJTwPE'
form_id = card.get('formId')
payload = {}
payload['touser'] = openId
payload['template_id'] = template_id
payload['form_id'] = form_id
payload['page'] = 'pages/detail/detail?id='+card.id
payload['emphasis_keyword'] = 'keyword3.DATA'
keyword1 = { "value": "码图"}
keyword2 = { "value": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
keyword3 = { "value": "审核通过"}
keyword4 = { "value": "用户创作"}
data = { "keyword1": keyword1, "keyword2": keyword2, "keyword3": keyword3, "keyword4": keyword4 }
payload['data'] = data
app_id = os.environ["WXA_APP_ID"]
app_secret = os.environ["WXA_APP_SECRET"]
wx = weixin(app_id,app_secret)
ret = wx.template_send(payload);
return ret
def review(request,id):
try:
query = Card.query
query.include('user')
card = query.get(id)
if(card):
update = Card.create_without_data(id)
update.set('publish',True)
update.set('deleted',False)
update.set('publishAt',datetime.datetime.now())
if(card.get('formId')):
data = template_send(card)
update.save()
#return HttpResponse(json.dumps(str(data)),content_type="application/json")
ret = {'code':200,'message':'审核通过'}
return HttpResponse(json.dumps(ret),content_type="application/json")
else:
ret = {'code':203,'message':'词卡不存在'}
return HttpResponse(json.dumps(ret),content_type="application/json")
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="application/json")
else:
raise e
return HttpResponse(e,content_type="application/json")
def publish(request,id):
try:
query = Card.query
query.include('user')
card = query.get(id)
if(card):
update = Card.create_without_data(id)
user = User.create_without_data('590be679ac502e006cdc63c0')
update.set('publish',True)
update.set('deleted',False)
update.set('user',user)
update.set('publishAt',datetime.datetime.now())
if(card.get('formId')):
data = template_send(card)
update.save()
Movie.generate(card)
#return HttpResponse(json.dumps(str(data)),content_type="application/json")
ret = {'code':200,'message':'审核通过'}
return HttpResponse(json.dumps(ret),content_type="application/json")
else:
ret = {'code':203,'message':'词卡不存在'}
return HttpResponse(json.dumps(ret),content_type="application/json")
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="application/json")
else:
raise e
return HttpResponse(e,content_type="application/json")
def reject(request,id):
try:
query = Card.query
query.include('user')
card = query.get(id)
if(card):
update = Card.create_without_data(id)
update.set('deleted',True)
update.set('publish',False)
#update.set('publishAt',datetime.now())
#if(card.get('formId')):
#data = template_send(card)
update.save()
#return HttpResponse(json.dumps(str(data)),content_type="application/json")
ret = {'code':200,'message':'审核通过'}
return HttpResponse(json.dumps(ret),content_type="application/json")
else:
ret = {'code':203,'message':'词卡不存在'}
return HttpResponse(json.dumps(ret),content_type="application/json")
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="application/json")
else:
raise e
return HttpResponse(e,content_type="application/json")
def recall(request,id):
try:
query = Card.query
query.include('user')
card = query.get(id)
if(card):
update = Card.create_without_data(id)
update.set('publish',False)
#update.set('publishAt',datetime.now())
#if(card.get('formId')):
#data = template_send(card)
update.save()
#return HttpResponse(json.dumps(str(data)),content_type="application/json")
ret = {'code':200,'message':'审核通过'}
return HttpResponse(json.dumps(ret),content_type="application/json")
else:
ret = {'code':203,'message':'词卡不存在'}
return HttpResponse(json.dumps(ret),content_type="application/json")
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="application/json")
else:
raise e
return HttpResponse(e,content_type="application/json")
def generate(request,id):
try:
card = Query(Card).get(id)
tid = card.get('template')
if(card.get('photo') is None):
msstream = BytesIO()
if tid == 1:
template(card,msstream)
elif tid == 2:
template2(card,msstream)
elif tid == 3:
template3(card,msstream)
elif tid == 4:
template4(card,msstream)
else:
template(card,msstream)
url = os.environ["QINIU_ACCESS_URL"]
access_key = os.environ["QINIU_ACCESS_KEY"]
secret_key = os.environ["QINIU_SECRET_KEY"]
#构建鉴权对象
q = Auth(access_key, secret_key)
#要上传的空间
bucket_name = 'card'
key = card.get('objectId')
token = q.upload_token(bucket_name)
ret, info = put_data(token, key, msstream.getvalue())
if(info.ok()):
metaData = {'owner':card.get('username')}
photo = Photo()
photo.set('mine_type','image/jpeg')
photo.set('key',key)
photo.set('name',key)
photo.set('url',url+'/'+key)
photo.set('provider','qiniu')
photo.set('metaData',metaData)
photo.set('bucket',bucket_name)
photo.save()
update = Card.create_without_data(id)
update.set('photo',photo)
update.save()
return HttpResponse(json.dumps(ret),content_type="text/plain")
else:
return HttpResponse('failed',content_type="text/plain")
else:
return HttpResponse('already',content_type="text/plain")
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="text/plain")
else:
raise e
return HttpResponse(e,content_type="text/plain")
def generateCloud(card):
try:
tid = card.get('template')
if(card.get('photo') is None):
msstream = BytesIO()
if tid == 1:
template(card,msstream)
elif tid == 2:
template2(card,msstream)
elif tid == 3:
template3(card,msstream)
elif tid == 4:
template4(card,msstream)
else:
template(card,msstream)
url = os.environ["QINIU_ACCESS_URL"]
access_key = os.environ["QINIU_ACCESS_KEY"]
secret_key = os.environ["QINIU_SECRET_KEY"]
#构建鉴权对象
q = Auth(access_key, secret_key)
#要上传的空间
bucket_name = 'card'
key = card.get('objectId')
token = q.upload_token(bucket_name)
ret, info = put_data(token, key, msstream.getvalue())
if(info.ok()):
metaData = {'owner':card.get('username')}
photo = Photo()
photo.set('mine_type','image/jpeg')
photo.set('key',key)
photo.set('name',key)
photo.set('url',url+'/'+key)
photo.set('provider','qiniu')
photo.set('metaData',metaData)
photo.set('bucket',bucket_name)
photo.save()
update = Card.create_without_data(key)
update.set('photo',photo)
update.save()
return 'ok'
else:
return 'failed'
return 'already'
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="text/plain")
else:
raise e
return HttpResponse(e,content_type="text/plain")
def preview(request,id):
try:
card = Query(Card).get(id)
tid = card.get('template')
type = card.get('type')
msstream = BytesIO()
data = {'copyright':'天天码图','author':card.get('author'),'id':card.id,'url':card.get('img_url'),'title':card.get('name'),'content':card.get('content')}
if type == 'movie':
Movie.movie(data,msstream)
elif type == 'music':
Music.music(data,msstream)
elif type == 'book':
Book.book(data,msstream)
else:
if tid == 1:
template(card,msstream)
elif tid == 2:
template2(card,msstream)
elif tid == 3:
template3(card,msstream)
elif tid == 4:
template4(card,msstream)
else:
template(card,msstream)
return HttpResponse(msstream.getvalue(),content_type="image/png")
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="text/plain")
else:
raise e
return HttpResponse(e,content_type="text/plain")
def download(request,id):
try:
card = Query(Card).get(id)
tid = card.get('template')
type = card.get('type')
msstream = BytesIO()
data = {'copyright':'天天码图','author':card.get('author'),'id':card.id,'url':card.get('img_url'),'title':card.get('name'),'content':card.get('content')}
if type == 'movie':
Movie.movie(data,msstream)
elif type == 'music':
Music.music(data,msstream)
elif type == 'book':
Book.book(data,msstream)
else:
if tid == 1:
template(card,msstream)
elif tid == 2:
template2(card,msstream)
elif tid == 3:
template3(card,msstream)
elif tid == 4:
template4(card,msstream)
else:
template(card,msstream)
return HttpResponse(msstream.getvalue(),content_type="image/png")
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="text/plain")
else:
raise e
return HttpResponse(e,content_type="text/plain")
def template(card,msstream):
w = 640
h = 862
iw = 600
ih = 340
title = card.get('name')
content = card.get('content')
url = card.get('img_url')
spacing = 20
content = fill(content, 15)
author = '- 天天码图 -'
copyright = '微信小程序「天天码图」'
title_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 35)
content_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 30)
author_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 25)
copyright_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 25)
base = Image.new('RGBA',(w,h),(255,255,255,255))
draw = ImageDraw.Draw(base)
if len(title) > 0:
tw,th = draw.multiline_textsize(title, font=title_fnt)
else:
th =0
aw,ah = draw.multiline_textsize(author, font=author_fnt)
cw,ch = draw.multiline_textsize(content, font=content_fnt, spacing=spacing)
crw,crh = draw.multiline_textsize(copyright, font=copyright_fnt)
h = 635+th+ch+crh+ah;
base = Image.new('RGBA',(w,h),(255,255,255,255))
draw = ImageDraw.Draw(base)
file = BytesIO(urllib.request.urlopen(url).read())
photo = Image.open(file).convert('RGBA')
(pw, ph) = photo.size
if pw/ph>iw/ih:
box = ((pw-ph*iw/ih)/2,0,(pw+ph*iw/ih)/2,ph)
else:
box = (0,(ph-pw*ih/iw)/2,pw,(ph+pw*ih/iw)/2)
photo = photo.crop(box)
photo = photo.resize((iw,ih))
base.paste(photo,box=(20,20))
# get a drawing context
draw = ImageDraw.Draw(base)
# draw text in the middle of the image, half opacity
if len(title) > 0:
draw.multiline_text((w/2-tw/2,420), title, font=title_fnt, fill=(0,0,0,255), align='center')
draw.multiline_text((w/2-cw/2,420+th+45), content, font=content_fnt, fill=(0,0,0,255), align='center', spacing=spacing)
draw.multiline_text((w/2-aw/2,420+th+45+ch+115), author, font=author_fnt, fill=(0,0,0,255), align='center')
draw.multiline_text((w-crw,420+th+45+ch+115+ah+50), copyright, font=copyright_fnt, fill=(189,189,189,255), align='center')
# save image data to output stream
base.save(msstream,"jpeg")
# release memory
base.close()
def template2(card,msstream):
w = 640
h = 1020
iw = 600
ih = 340
title = card.get('name')
content = card.get('content')
url = card.get('img_url')
spacing = 20
padding = 2
author = '- 天天码图 -'
copyright = '微信小程序「天天码图」'
title_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 35)
content_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 30)
author_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 25)
copyright_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 25)
base = Image.new('RGBA',(w,h),(255,255,255,255))
draw = ImageDraw.Draw(base)
aw,ah = draw.multiline_textsize(author, font=author_fnt)
crw,crh = draw.multiline_textsize(copyright, font=copyright_fnt)
file = BytesIO(urllib.request.urlopen(url).read())
photo = Image.open(file).convert('RGBA')
(pw, ph) = photo.size
if pw/ph>iw/ih:
box = ((pw-ph*iw/ih)/2,0,(pw+ph*iw/ih)/2,ph)
else:
box = (0,(ph-pw*ih/iw)/2,pw,(ph+pw*ih/iw)/2)
photo = photo.crop(box)
photo = photo.resize((iw,ih))
base.paste(photo,box=(20,20))
# get a drawing context
draw = ImageDraw.Draw(base)
# split the title
tlines = wrap(title, 1)
# current title height
tnh = 420
# get width and height of single title word
stw,sth = title_fnt.getsize("已")
for tline in tlines:
draw.text((w-115-stw,tnh), tline, fill=(0,0,0,255), font=title_fnt)
tnh = tnh+sth
# get width and height of single content word
scw,sch = content_fnt.getsize("已")
clines = wrap(content, 14)
# current width of content
cnw = w-115-stw-115-scw
for cline in clines:
# current height of content
cnh = 420
cwords = wrap(cline, 1)
for cword in cwords:
pattern = re.compile("[,。、]+")
if pattern.search(cword):
draw.text((cnw,cnh), cword, fill=(0,0,0,255), font=content_fnt)
# draw.text((cnw+30-12,cnh-30+12), cword, fill=(0,0,0,255), font=content_fnt)
else:
draw.text((cnw,cnh), cword, fill=(0,0,0,255), font=content_fnt)
cnh = cnh+sch+padding
cnw = cnw-scw-spacing
# draw text in the middle of the image, half opacity
# draw.multiline_text((w/2-tw/2,420), title, font=title_fnt, fill=(0,0,0,255), align='center')
# draw.multiline_text((w/2-cw/2,420+th+45), content, font=content_fnt, fill=(0,0,0,255), align='center', spacing=spacing)
draw.multiline_text((w/2-aw/2,h-50-15-crh-ah), author, font=author_fnt, fill=(0,0,0,255), align='center')
draw.multiline_text((w-crw,h-15-crh), copyright, font=copyright_fnt, fill=(189,189,189,255), align='center')
# save image data to output stream
base.save(msstream,"jpeg")
# release memory
base.close()
def template3(card,msstream):
w = 640
h = 862
iw = 600
ih = 340
bw = 300
bh = 300
title = card.get('name')
content = card.get('content')
url = card.get('img_url')
spacing = 20
content = fill(content, 15)
author = '- 天天码图 -'
copyright = '微信小程序「天天码图」'
title_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 35)
content_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 30)
author_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 25)
copyright_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 25)
base = Image.new('RGBA',(w,h),(255,255,255,255))
draw = ImageDraw.Draw(base)
tw,th = draw.multiline_textsize(title, font=title_fnt)
aw,ah = draw.multiline_textsize(author, font=author_fnt)
cw,ch = draw.multiline_textsize(content, font=content_fnt, spacing=spacing)
crw,crh = draw.multiline_textsize(copyright, font=copyright_fnt)
h = 695+th+ch+crh+ah;
base = Image.new('RGBA',(w,h),(255,255,255,255))
draw = ImageDraw.Draw(base)
file = BytesIO(urllib.request.urlopen(url).read())
photo = Image.open(file).convert('RGBA')
pw, ph = photo.size
if pw > ph:
box = ((pw-ph*bw/bh)/2,0,(pw+ph*bw/bh)/2,ph)
else:
box = (0,(ph-pw*bh/bw)/2,pw,(ph+pw*bh/bw)/2)
photo = photo.crop(box)
photo = photo.resize((bw*4,bh*4))
circle = Image.new('L', (bw*4, bh*4), 0)
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, bw*4, bh*4), fill=255)
alpha = Image.new('L', (bw*4, bh*4), 255)
alpha.paste(circle, (0, 0))
photo.putalpha(alpha)
photo = photo.resize((bw,bh),Image.ANTIALIAS)
base.paste(photo,box=(170,120),mask=photo)
# get a drawing context
draw = ImageDraw.Draw(base)
# draw text in the middle of the image, half opacity
draw.multiline_text((w/2-tw/2,480), title, font=title_fnt, fill=(0,0,0,255), align='center')
draw.multiline_text((w/2-cw/2,480+th+45), content, font=content_fnt, fill=(0,0,0,255), align='center', spacing=spacing)
draw.multiline_text((w/2-aw/2,480+th+45+ch+115), author, font=author_fnt, fill=(0,0,0,255), align='center')
draw.multiline_text((w-crw,480+th+45+ch+115+ah+50), copyright, font=copyright_fnt, fill=(189,189,189,255), align='center')
# save image data to output stream
base.save(msstream,"jpeg")
# release memory
base.close()
def template4(card,msstream):
w = 640
h = 1080
iw = 600
ih = 340
bw = 300
bh = 300
padding = 2
title = card.get('name')
content = card.get('content')
url = card.get('img_url')
spacing = 20
content = fill(content, 15)
author = '- 天天码图 -'
copyright = '微信小程序「天天码图」'
title_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 35)
content_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 30)
author_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 25)
copyright_fnt = ImageFont.truetype('font/zh/YueSong.ttf', 25)
base = Image.new('RGBA',(w,h),(255,255,255,255))
draw = ImageDraw.Draw(base)
aw,ah = draw.multiline_textsize(author, font=author_fnt)
crw,crh = draw.multiline_textsize(copyright, font=copyright_fnt)
file = BytesIO(urllib.request.urlopen(url).read())
photo = Image.open(file).convert('RGBA')
pw, ph = photo.size
if pw > ph:
box = ((pw-ph*bw/bh)/2,0,(pw+ph*bw/bh)/2,ph)
else:
box = (0,(ph-pw*bh/bw)/2,pw,(ph+pw*bh/bw)/2)
photo = photo.crop(box)
photo = photo.resize((bw*4,bh*4))
circle = Image.new('L', (bw*4, bh*4), 0)
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, bw*4, bh*4), fill=255)
alpha = Image.new('L', (bw*4, bh*4), 255)
alpha.paste(circle, (0, 0))
photo.putalpha(alpha)
photo = photo.resize((bw,bh),Image.ANTIALIAS)
base.paste(photo,box=(170,120),mask=photo)
# get a drawing context
draw = ImageDraw.Draw(base)
# split the title
tlines = wrap(title, 1)
# current title height
tnh = 480
# get width and height of single title word
stw,sth = title_fnt.getsize("已")
for tline in tlines:
draw.text((w-115-stw,tnh), tline, fill=(0,0,0,255), font=title_fnt)
tnh = tnh+sth
# get width and height of single content word
scw,sch = content_fnt.getsize("已")
clines = wrap(content, 14)
# current width of content
cnw = w-115-stw-115-scw
for cline in clines:
# current height of content
cnh = 480
cwords = wrap(cline, 1)
for cword in cwords:
pattern = re.compile("[,。、]+")
if pattern.search(cword):
draw.text((cnw,cnh), cword, fill=(0,0,0,255), font=content_fnt)
# draw.text((cnw+30-12,cnh-30+12), cword, fill=(0,0,0,255), font=content_fnt)
else:
draw.text((cnw,cnh), cword, fill=(0,0,0,255), font=content_fnt)
cnh = cnh+sch+padding
cnw = cnw-scw-spacing
# draw text in the middle of the image, half opacity
# draw.multiline_text((w/2-tw/2,420), title, font=title_fnt, fill=(0,0,0,255), align='center')
# draw.multiline_text((w/2-cw/2,420+th+45), content, font=content_fnt, fill=(0,0,0,255), align='center', spacing=spacing)
draw.multiline_text((w/2-aw/2,h-50-15-crh-ah), author, font=author_fnt, fill=(0,0,0,255), align='center')
draw.multiline_text((w-crw,h-15-crh), copyright, font=copyright_fnt, fill=(189,189,189,255), align='center')
# save image data to output stream
base.save(msstream,"jpeg")
# release memory
base.close()