upload
This commit is contained in:
commit
21851bf8c5
61 files changed
+5260
No files matched your search
@@ -0,0 +1,32 @@
|
||||
"""從 icon/ 裡的圖片產生網頁用的圖:
|
||||
|
||||
server/.venv/Scripts/python tools/make_icons.py # 用 icon/ 裡的第一張圖當圖標
|
||||
server/.venv/Scripts/python tools/make_icons.py icon/x.png
|
||||
|
||||
吱吱影片另外用 tools/make_media.py 轉檔。
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
WEB = ROOT / "web"
|
||||
IMG_EXTS = {".png", ".jpg", ".jpeg", ".webp"}
|
||||
|
||||
src = Path(sys.argv[1]) if len(sys.argv) > 1 else next(
|
||||
p for p in sorted((ROOT / "icon").iterdir()) if p.is_file() and p.suffix.lower() in IMG_EXTS)
|
||||
with Image.open(src) as im:
|
||||
im = ImageOps.exif_transpose(im).convert("RGB")
|
||||
im = ImageOps.fit(im, (512, 512), Image.LANCZOS) # 不是正方形時置中裁切
|
||||
|
||||
im.save(WEB / "favicon.ico", sizes=[(16, 16), (32, 32), (48, 48)])
|
||||
for name, size in {"icon-192.png": 192, "icon-512.png": 512, "apple-touch-icon.png": 180, "logo.png": 64}.items():
|
||||
im.resize((size, size), Image.LANCZOS).save(WEB / name, optimize=True)
|
||||
print(f"{src.name} -> web/favicon.ico, icon-192.png, icon-512.png, apple-touch-icon.png, logo.png")
|
||||
|
||||
# 圖庫(image/)是空的時候,小卡上方用這張
|
||||
assets = ROOT / "server" / "app" / "assets"
|
||||
assets.mkdir(exist_ok=True)
|
||||
im.save(assets / "default-meme.jpg", "JPEG", quality=90)
|
||||
print(f"{src.name} -> server/app/assets/default-meme.jpg")
|
||||
@@ -0,0 +1,45 @@
|
||||
"""把 media-src/zhizhi.mp4(吱吱影片原檔)轉成網頁用的檔案:
|
||||
|
||||
server/.venv/Scripts/python -m pip install imageio-ffmpeg # 自帶 ffmpeg,不用另外安裝
|
||||
server/.venv/Scripts/python tools/make_media.py
|
||||
|
||||
輸出:
|
||||
web/media/zhizhi.mp4 H.264 + AAC、moov 放在檔頭(faststart),手機瀏覽器可以邊載邊播
|
||||
web/media/zhizhi-poster.webp 第一幀;還沒點擊時顯示的畫面
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import imageio_ffmpeg
|
||||
from PIL import Image
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
SRC = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / "media-src" / "zhizhi.mp4"
|
||||
MEDIA = ROOT / "web" / "media"
|
||||
FFMPEG = imageio_ffmpeg.get_ffmpeg_exe()
|
||||
|
||||
|
||||
def ffmpeg(*args: str) -> None:
|
||||
subprocess.run([FFMPEG, "-hide_banner", "-loglevel", "error", "-y", *args], check=True)
|
||||
|
||||
|
||||
MEDIA.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
video = MEDIA / "zhizhi.mp4"
|
||||
ffmpeg("-i", str(SRC),
|
||||
"-c:v", "libx264", "-profile:v", "main", "-pix_fmt", "yuv420p", "-crf", "23", "-preset", "slow",
|
||||
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2",
|
||||
"-c:a", "aac", "-b:a", "128k", "-ac", "2",
|
||||
"-movflags", "+faststart", str(video))
|
||||
|
||||
frame = MEDIA / "_first.png"
|
||||
ffmpeg("-i", str(SRC), "-frames:v", "1", str(frame))
|
||||
with Image.open(frame) as im:
|
||||
im = im.convert("RGB")
|
||||
im.save(MEDIA / "zhizhi-poster.webp", "WEBP", quality=88, method=6)
|
||||
size = im.size
|
||||
frame.unlink()
|
||||
|
||||
print(f"{SRC.name} -> web/media/zhizhi.mp4 ({video.stat().st_size // 1024} KB), "
|
||||
f"zhizhi-poster.webp {size[0]}x{size[1]}")
|
||||
Reference in new issue
Block a user