from PIL import Image, ImageDraw, ImageFont

F = '/usr/share/fonts/truetype/wlg/Montserrat.ttf'
def f(s, n='Bold'):
    ft = ImageFont.truetype(F, s)
    try: ft.set_variation_by_name(n)
    except Exception: pass
    return ft

TEAL=(0,81,81); AMBER=(243,174,61); SKY=(175,214,230); WHITE=(255,255,255)
W,H=1200,1500; M=100; RW=W-2*M

def wrap(d, text, font, maxw):
    lines, cur = [], ''
    for w in text.split():
        t = (cur+' '+w).strip()
        if d.textlength(t, font=font) <= maxw: cur = t
        else:
            if cur: lines.append(cur)
            cur = w
    if cur: lines.append(cur)
    return lines

def block(d, y, text, font, fill, lh, maxw=RW, x=M):
    for ln in wrap(d, text, font, maxw):
        d.text((x, y), ln, font=font, fill=fill); y += lh
    return y

QUOTES = [
 ('“Liubov clearly understood both: the technical depth and the leadership qualities we needed, the shortlist reflected that precision.”',
  'Marcin Basaj, Transformation and IT Director. Ex-EY-Parthenon, Ex-Citi'),
 ('“We have worked with Liubov and WLG Group for the last 5 years... What I appreciate most is that Liubov and her team stay connected even after the placement.”',
  'Nagesh Polu, Enterprise AI for HR and Business Leaders'),
 ('“Not only did WLG understand our technical requirements, but also manage to find the right personality.”',
  'Dennis Glitten, Manager, IT development and operations. Banking and cloud'),
 ('“Work life group has the ability to squeeze out candidates even in the narrowest of qualifications and competencies.”',
  'Zyshan Chowdary, Senior D365 Project Manager, Director'),
]

im = Image.new('RGB',(W,H),TEAL); d = ImageDraw.Draw(im)
d.rectangle([0,0,W,10], fill=AMBER)
d.text((M,78), 'WLG', font=f(44,'Bold'), fill=AMBER)
_sf = f(22,'SemiBold')
_st = '  '.join(list('BEYOND BORDERS')).replace('     ','    ')
d.text((W-M-d.textlength(_st, font=_sf), 92), _st, font=_sf, fill=AMBER)
d.text((M,178), '  '.join(list('WHAT CLIENTS SAY')), font=f(22,'SemiBold'), fill=SKY)
d.text((M,226), 'In their words, not ours.', font=f(38,'SemiBold'), fill=WHITE)

qf = f(28,'Regular'); af = f(23,'Medium')
y = 378
for q, who in QUOTES:
    lines = wrap(d, q, qf, RW-56)
    h = 40*len(lines)
    d.rectangle([M, y-6, M+6, y+h-14], fill=AMBER)
    yy = y
    for ln in lines:
        d.text((M+42, yy), ln, font=qf, fill=WHITE); yy += 40
    ay = block(d, yy+16, who, af, SKY, 32, RW-56, M+42)
    y = ay + 62

kf = f(38,'SemiBold')
kl = wrap(d, 'Fifteen of these sit on the profile.', kf, RW)
ky = 1352 - 50*len(kl)
d.rectangle([M, ky-54, M+140, ky-48], fill=AMBER)
block(d, ky, 'Fifteen of these sit on the profile.', kf, WHITE, 50)
d.text((M,1418), 'Quoted word for word.  Senior and director level technology hiring.',
       font=f(23,'Medium'), fill=SKY)

im.save('/workspace/pub/case_quotes.png','PNG')
print('ok', im.size, 'last block ended at', y)
