mirror of
				https://git.sr.ht/~tsileo/microblog.pub
				synced 2025-06-05 21:59:23 +02:00 
			
		
		
		
	Generate a basic favicon dynamically
This commit is contained in:
		
							
								
								
									
										22
									
								
								app/utils/favicon.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								app/utils/favicon.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
import sass  # type: ignore
 | 
			
		||||
from PIL import Image
 | 
			
		||||
from PIL import ImageColor
 | 
			
		||||
from PIL import ImageDraw
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _get_primary_color() -> str:
 | 
			
		||||
    """Small hack to get the theme primary color."""
 | 
			
		||||
    compiled = sass.compile(
 | 
			
		||||
        string=(
 | 
			
		||||
            "@import 'app/scss/main.scss';\n"
 | 
			
		||||
            "#favicon-color { color: $primary-color; }"
 | 
			
		||||
        )
 | 
			
		||||
    )
 | 
			
		||||
    return compiled[len(compiled) - 11 : -4]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def build_favicon() -> None:
 | 
			
		||||
    """Builds a basic favicon with the theme primary color."""
 | 
			
		||||
    im = Image.new("RGB", (32, 32), ImageColor.getrgb(_get_primary_color()))
 | 
			
		||||
    ImageDraw.Draw(im)
 | 
			
		||||
    im.save("app/static/favicon.ico")
 | 
			
		||||
		Reference in New Issue
	
	Block a user