sync chunk 11/12
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import io, sys
|
||||
|
||||
src = Path(sys.argv[1])
|
||||
out = Path(sys.argv[2])
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
items = []
|
||||
with ZipFile(src) as zf:
|
||||
for name in zf.namelist():
|
||||
if name.startswith("word/media/"):
|
||||
data = zf.read(name)
|
||||
target = out / Path(name).name
|
||||
target.write_bytes(data)
|
||||
try:
|
||||
im = Image.open(io.BytesIO(data)).convert("RGB")
|
||||
items.append((target.name, im.copy(), im.size))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
thumb_w, thumb_h = 300, 220
|
||||
sheet = Image.new("RGB", (thumb_w * 4, (thumb_h + 36) * ((len(items)+3)//4)), "white")
|
||||
draw = ImageDraw.Draw(sheet)
|
||||
for i, (name, im, size) in enumerate(items):
|
||||
x, y = (i % 4) * thumb_w, (i // 4) * (thumb_h + 36)
|
||||
im.thumbnail((thumb_w-10, thumb_h-10))
|
||||
sheet.paste(im, (x + (thumb_w-im.width)//2, y + 5))
|
||||
draw.text((x+5, y+thumb_h+3), f"{name} {size[0]}x{size[1]}", fill="black")
|
||||
sheet.save(out / "contact_sheet.jpg", quality=90)
|
||||
print(f"extracted={len(items)} sheet={out/'contact_sheet.jpg'}")
|
||||
Reference in New Issue
Block a user