"""Crop the journal asset to the actual notebook bounds (removing the baked-in
cream margin) so the notebook fills the content area and reads much larger.
Keeps the feathered alpha edges for the soft botanical fade.
"""
from PIL import Image
import numpy as np

SRC = r'C:\Users\danam\SGT-FANTASTIC-08-06-26\Local\PixieSprout\assets\pixiesprout\notebook\journal-fullpage.png'
OUT = r'C:\Users\danam\SGT-FANTASTIC-08-06-26\Local\PixieSprout\assets\pixiesprout\notebook\journal-fullpage-cropped.png'

im = Image.open(SRC).convert('RGBA')
a = np.array(im)
w, h = im.size

# Find the solid notebook bounds (alpha > 200)
alpha = a[:, :, 3]
solid = alpha > 200
rows = np.where(solid.any(axis=1))[0]
cols = np.where(solid.any(axis=0))[0]
y0, y1 = rows.min(), rows.max()
x0, x1 = cols.min(), cols.max()

# Add a tiny padding so the feathered botanical edge is preserved
pad = 4
x0 = max(0, x0 - pad)
y0 = max(0, y0 - pad)
x1 = min(w, x1 + pad)
y1 = min(h, y1 + pad)

crop = im.crop((x0, y0, x1, y1))
crop.save(OUT)
print('cropped to', crop.size, 'from', (x0, y0, x1, y1))
print('new aspect:', round(crop.size[0] / crop.size[1], 4))
