Skip to content

Commit

Permalink
Switch all images to be loaded via base64 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohankapoorcom authored Aug 22, 2024
1 parent c010c99 commit a37376d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
venv
10 changes: 9 additions & 1 deletion create-themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pathlib import Path

import base64
import jinja2
import yaml
from PIL import Image
Expand All @@ -24,6 +25,12 @@ def average_color(fname):
return "rgba({}, {}, {}, 0.4)".format(*rgb_color)


def base64_encode_file(fname):
with open(fname, 'rb') as image_file:
extension = fname.suffix.split('.')[-1]
base64_utf8_str = base64.b64encode(image_file.read()).decode('utf-8')
return f'data:image/{extension};base64,{base64_utf8_str}'

BACKGROUND_COLORS = {
# Suggested by @okets in issue #42
"blue-red": "rgba(30, 2, 61, 0.4)",
Expand Down Expand Up @@ -68,7 +75,8 @@ def average_color(fname):
folder=folder,
which=which,
app_header_background_color=app_header_background_color,
background_jpg=str(background.name),
background_jpg=base64_encode_file(background),
# background_jpg=str(background.name),
color=color,
suffix=suffix,
)
Expand Down
56 changes: 28 additions & 28 deletions manual-install/ios-themes.yaml

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
pre-commit
yamllint
Jinja2==3.1.4
pillow==10.3.0
pre-commit==3.7.1
PyYAML==6.0.1
yamllint==1.35.1
2 changes: 1 addition & 1 deletion template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
ios-{{ which }}-mode-{{ color }}{{ suffix }}:
# Global
background-image: "center / cover no-repeat fixed url('/{{ folder }}/themes/ios-themes/{{ background_jpg }}')"
background-image: "center / cover no-repeat fixed url('{{ background_jpg }}')"
lovelace-background: var(--background-image)
primary-color: {{ primary_color }} # from Apple systemOrange {{ which }} mode
light-primary-color: {{ light_primary_color }} # (icons on left menu) (light: systemGray5 from iOS dark mode, dark: XXX)
Expand Down
56 changes: 28 additions & 28 deletions themes/ios-themes.yaml

Large diffs are not rendered by default.

0 comments on commit a37376d

Please sign in to comment.