from PIL import Image, ImageDraw, ImageFont, ImageEnhance, ImageFilter

src='/home/spazio/.hermes/cache/images/img_5384b6302ca1.jpg'
out='/home/spazio/cosmos_luminosity_editorial_v2.jpg'
W,H=1080,1350
orig=Image.open(src).convert('RGB')

# Build a clean editorial split: use only the text-free/right photographic zone.
# Crop right side, enlarge subtly and place from x=420.
photo=orig.crop((425,0,1080,1350)).resize((660,1350),Image.Resampling.LANCZOS)
photo=ImageEnhance.Color(photo).enhance(.88)
photo=ImageEnhance.Contrast(photo).enhance(1.07)
photo=ImageEnhance.Brightness(photo).enhance(.92)

canvas=Image.new('RGB',(W,H),(24,10,39))
canvas.paste(photo,(420,0))

# Clean top/bottom remnants on photo with localized cinematic washes.
over=Image.new('RGBA',(W,H),(0,0,0,0)); op=over.load()
for y in range(H):
  for x in range(W):
    a=0
    if y<118: a=max(a,int(150*(1-y/118)))
    if y>1190: a=max(a,int(135*((y-1190)/160)))
    # seamless aubergine bridge into photo, intentional rather than accidental
    if 380<x<560:
      a=max(a,int(235*(1-(x-380)/180)**1.4))
    op[x,y]=(18,8,31,a)
canvas=Image.alpha_composite(canvas.convert('RGBA'),over)
d=ImageDraw.Draw(canvas)

# Fully clean the two areas where source artwork contained baked-in utility text.
# These are intentional editorial bars, not attempts to blur text away.
d.rectangle((420,0,1080,104),fill=(18,8,31,235))
d.rectangle((420,1238,1080,1350),fill=(18,8,31,245))

serif='/home/spazio/.fonts/cl/PlayfairDisplay-Bold.ttf'
sans='/home/spazio/.fonts/cl/Manrope.ttf'
WHITE=(248,244,236,255)
VIOLET=(183,130,235,255)
YELLOW=(247,210,68,255)
GOLD=(203,164,85,255)
PALE=(220,210,225,255)

# clean editorial structure
d.text((58,54),'COSMOS LUMINOSITY',font=ImageFont.truetype(sans,19),fill=GOLD)
d.text((362,54),'Q03',font=ImageFont.truetype(sans,19),fill=YELLOW,anchor='ra')
d.line((58,91,362,91),fill=GOLD,width=1)

# Accent monolith: thin yellow rail
d.rectangle((58,156,64,318),fill=YELLOW)

# Fit line helper

def fit(text,maxw,start,minsize,fontpath=serif):
  for s in range(start,minsize-1,-1):
    f=ImageFont.truetype(fontpath,s)
    if d.textbbox((0,0),text,font=f)[2] <= maxw: return f
  return ImageFont.truetype(fontpath,minsize)

x=86; y=150; maxw=310
for text,color,size in [
  ('Какой',WHITE,58),
  ('вариант',VIOLET,68),
  ('ты пока',WHITE,56),
  ('даже не',WHITE,56),
  ('рассматриваешь?',YELLOW,48),
]:
  f=fit(text,maxw,size,29)
  d.text((x,y),text,font=f,fill=color)
  y=d.textbbox((x,y),text,font=f)[3]+3

# precise supporting thought, no heavy slogan
rule_y=650
d.line((58,rule_y,152,rule_y),fill=GOLD,width=2)
body=ImageFont.truetype(sans,24)
for i,line in enumerate([
  'Старый вывод',
  'сужает обзор.',
  '',
  'Вопрос возвращает',
  'внимание к тому,',
  'что ещё не замечено.'
]):
  if line:
    d.text((58,rule_y+35+i*38),line,font=body,fill=PALE)

# subtle violet label over transition seam — connects palette to photo
label_font=ImageFont.truetype(sans,16)
d.rounded_rectangle((58,1055,304,1097),radius=21,fill=(117,66,160,230),outline=(190,137,235,180),width=1)
d.text((181,1076),'LIVING ATTENTION',font=label_font,fill=WHITE,anchor='mm')

# footer
foot=ImageFont.truetype(sans,16)
d.line((58,1258,1020,1258),fill=(203,164,85,110),width=1)
d.text((58,1284),'A LIVING INTERFACE OF ATTENTION',font=foot,fill=GOLD)
d.text((1020,1284),'04 / 07',font=foot,fill=WHITE,anchor='ra')

canvas.convert('RGB').save(out,quality=96,subsampling=0)
print(out)
