2023-03-26 19:57:10 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2023-03-25 16:12:38 +00:00
|
|
|
import requests
|
|
|
|
from cairosvg import svg2png
|
|
|
|
from pathlib import Path
|
|
|
|
from shutil import rmtree
|
|
|
|
import os
|
|
|
|
|
|
|
|
GITEA_ROOT = "https://gitea.com"
|
|
|
|
OUTPUT_DIR = Path(__file__).parent.resolve() / "output"
|
|
|
|
|
2023-03-25 16:16:41 +00:00
|
|
|
COLOUR_REPLACE = {
|
|
|
|
b"#609926": b"#e85537",
|
|
|
|
b"#fff": b"#0a0a0a"
|
|
|
|
}
|
|
|
|
|
2023-03-25 16:12:38 +00:00
|
|
|
|
|
|
|
def download_file(url: str):
|
|
|
|
print("Downloading", os.path.basename(url))
|
|
|
|
response = requests.get(url)
|
|
|
|
response.raise_for_status()
|
|
|
|
return response.content
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2023-03-26 20:01:41 +01:00
|
|
|
try:
|
|
|
|
rmtree(OUTPUT_DIR)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
2023-03-25 16:12:38 +00:00
|
|
|
OUTPUT_DIR.mkdir(exist_ok=True)
|
|
|
|
|
|
|
|
logo = download_file(f"{GITEA_ROOT}/assets/img/logo.svg")
|
|
|
|
favicon = download_file(f"{GITEA_ROOT}/assets/img/favicon.svg")
|
|
|
|
|
|
|
|
print("Rebranding...")
|
2023-03-25 16:16:41 +00:00
|
|
|
for old_colour, new_colour in COLOUR_REPLACE.items():
|
|
|
|
logo = logo.replace(old_colour, new_colour)
|
|
|
|
favicon = favicon.replace(old_colour, new_colour)
|
2023-03-25 16:12:38 +00:00
|
|
|
|
|
|
|
print("Resizing...")
|
|
|
|
svg2png(logo, write_to=str(OUTPUT_DIR / "logo.png"), output_height=512, output_width=512)
|
|
|
|
svg2png(logo, write_to=str(OUTPUT_DIR / "favicon.png"), output_height=180, output_width=180)
|
|
|
|
|
|
|
|
svg2png(logo, write_to=str(OUTPUT_DIR / "avatar_default.png"), output_height=200, output_width=200)
|
|
|
|
svg2png(logo, write_to=str(OUTPUT_DIR / "apple-touch-icon.png"), output_height=200, output_width=200)
|
|
|
|
|
|
|
|
(OUTPUT_DIR / "logo.svg").write_bytes(logo)
|
|
|
|
(OUTPUT_DIR / "favicon.svg").write_bytes(favicon)
|
|
|
|
(OUTPUT_DIR / "gitea.svg").write_bytes(favicon)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|