88 lines
2.8 KiB
Python
88 lines
2.8 KiB
Python
"""
|
|
Off-focal, crop-resistant candidates — keep the crisp corner look but park the
|
|
mark off the subject and out of easy-crop range.
|
|
|
|
corner — reference (clippable)
|
|
edge-rail — wordmark up a side margin at mid-height (auto-picks calmer side)
|
|
dual-corner — top-left + bottom-right; one crop can't remove both
|
|
|
|
Output: public/photos-watermarked/_preview/offfocal/
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
from watermark_lib import WatermarkStyle, render_watermark, FONT_DIR
|
|
|
|
REPO = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
|
|
PUB = os.path.join(REPO, "deployments/@domains/quinn.www/root/public/photos")
|
|
OUT = os.path.join(PUB + "-watermarked", "_preview", "offfocal")
|
|
CARD_W = 360
|
|
|
|
SAMPLES = [
|
|
("busy", f"{PUB}/quinn-pink-bra-boots-mural.jpeg"),
|
|
("bright", f"{PUB}/quinn-nude-bed-frontal.jpeg"),
|
|
]
|
|
MODES = [
|
|
("corner (clippable)", WatermarkStyle(mode="corner", position="bottom-right")),
|
|
("edge-rail (mid-height)", WatermarkStyle(mode="edge-rail", rail_width_frac=0.46)),
|
|
("dual-corner", WatermarkStyle(mode="dual-corner", text_width_frac=0.34)),
|
|
]
|
|
|
|
|
|
def label(im, text):
|
|
bar = 24
|
|
out = Image.new("RGB", (im.width, im.height + bar), (18, 18, 22))
|
|
out.paste(im, (0, 0))
|
|
try:
|
|
f = ImageFont.truetype(os.path.join(FONT_DIR, "Audiowide-Regular.ttf"), 13)
|
|
except Exception:
|
|
f = ImageFont.load_default()
|
|
ImageDraw.Draw(out).text((5, im.height + 5), text, fill=(255, 120, 190), font=f)
|
|
return out
|
|
|
|
|
|
def thumb(im, w=CARD_W):
|
|
return im.resize((w, round(im.height * w / im.width)), Image.LANCZOS)
|
|
|
|
|
|
def hstack(imgs, gap=12):
|
|
h = max(i.height for i in imgs)
|
|
out = Image.new("RGB", (sum(i.width for i in imgs) + gap * (len(imgs) - 1), h), (18, 18, 22))
|
|
x = 0
|
|
for i in imgs:
|
|
out.paste(i, (x, 0)); x += i.width + gap
|
|
return out
|
|
|
|
|
|
def crop_bottom(im, frac=0.18):
|
|
return im.crop((0, 0, im.width, int(im.height * (1 - frac))))
|
|
|
|
|
|
def main():
|
|
os.makedirs(OUT, exist_ok=True)
|
|
for sname, src in SAMPLES:
|
|
im = Image.open(src)
|
|
hstack([label(thumb(render_watermark(im, st)), ml) for ml, st in MODES]) \
|
|
.save(os.path.join(OUT, f"{sname}__modes.jpg"), quality=94)
|
|
|
|
im = Image.open(SAMPLES[0][1])
|
|
corner = render_watermark(im, MODES[0][1])
|
|
rail = render_watermark(im, MODES[1][1])
|
|
dual = render_watermark(im, MODES[2][1])
|
|
hstack([
|
|
label(thumb(crop_bottom(corner)), "corner — bottom crop: GONE"),
|
|
label(thumb(crop_bottom(rail)), "edge-rail — bottom crop: SURVIVES"),
|
|
label(thumb(crop_bottom(dual)), "dual-corner — bottom crop: 1 SURVIVES"),
|
|
]).save(os.path.join(OUT, "CROP_ATTACK.jpg"), quality=94)
|
|
|
|
print("written", OUT)
|
|
for f in sorted(os.listdir(OUT)):
|
|
print(" ", f)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|