#!/usr/bin/env python3 import os import sys import subprocess import json import requests import re from PIL import Image import time import math res_dir = '/var/www/logos/site/res' pb_image = '/var/www/logos/site/images/poweredby.png' pb_dir = '/var/www/logos/site/poweredby' projects = [x for x in os.listdir(res_dir) if os.path.isdir(os.path.join(res_dir, x))] for project in sorted(projects): dpath = '%s/%s/default_hr.png' % (res_dir, project) if os.path.exists('%s/%s/%s-pb_highres.png' % (res_dir, project, project)): dpath = '%s/%s/%s-pb_highres.png' % (res_dir, project, project) outpath = '%s/%s.png' % (pb_dir, project) if os.path.exists(dpath): try: st = os.stat(dpath) except: st = None if st and (st.st_mtime > (time.time() - 43200) or not os.path.exists(outpath)): back = Image.open(pb_image) front = Image.open('%s/%s/default_hr.png' % (res_dir, project)) w = front.width h = front.height to_edge = math.sqrt(((w/2)*(w/2)) + ((h/2)*(h/2))) while to_edge > 520: w *= 0.995 h *= 0.995 to_edge = math.sqrt(((w/2)*(w/2)) + ((h/2)*(h/2))) w = int(w) h = int(h) print("Generating 'Powered By' for %s (%u x %u)..." % (project, w, h)) size = (w, h) front.thumbnail(size, Image.ANTIALIAS) centerx = int((back.width/2) - (w/2)) centery = int((back.height/2) - (h/2)) back.paste(front, (centerx, centery), front) back.save('%s/%s.png' % (pb_dir, project), 'PNG')