24 lines
840 B
Python
24 lines
840 B
Python
"""Extract first frame + generate small static posters from animated webp."""
|
|
import sys
|
|
from PIL import Image
|
|
|
|
def main():
|
|
srcs = [
|
|
("Work_files/Planet/planet_mobile.webp", "Work_files/Planet/planet_poster_mobile.webp", 320),
|
|
("Work_files/Planet/planet_15fps.webp", "Work_files/Planet/planet_poster.webp", 400),
|
|
]
|
|
for src, out, max_w in srcs:
|
|
im = Image.open(src)
|
|
im.seek(0)
|
|
frame = im.convert("RGBA")
|
|
# downscale to the file's native width if larger
|
|
if frame.width > max_w:
|
|
h = round(frame.height * max_w / frame.width)
|
|
frame = frame.resize((max_w, h), Image.LANCZOS)
|
|
frame.save(out, "WEBP", quality=75, method=6)
|
|
import os
|
|
print(f"{out}: {frame.size} {os.path.getsize(out)} bytes")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|