mirror of
https://github.com/MiSTer-devel/Distribution_MiSTer.git
synced 2026-05-24 03:03:20 +00:00
Update db_operator.py
Refactoring image code
This commit is contained in:
committed by
GitHub
parent
3a7f82a70d
commit
0be700b295
44
.github/db_operator.py
vendored
44
.github/db_operator.py
vendored
@@ -312,16 +312,14 @@ class Tags:
|
||||
self._append(result, self._use_term('filters_video'))
|
||||
|
||||
elif parent in ['wallpapers']:
|
||||
try:
|
||||
ar = image_aspect_ratio(path)
|
||||
if abs(ar - 1.77) < 0.1:
|
||||
self._append(result, self._use_term('ar16:9'))
|
||||
elif abs(ar - 1.33) < 0.1:
|
||||
self._append(result, self._use_term('ar4:3'))
|
||||
ar = read_image_aspect_ratio(path)
|
||||
if ar is None:
|
||||
pass
|
||||
elif abs(ar - 1.77) < 0.1:
|
||||
self._append(result, self._use_term('ar16:9'))
|
||||
elif abs(ar - 1.33) < 0.1:
|
||||
self._append(result, self._use_term('ar4:3'))
|
||||
|
||||
except Exception as e:
|
||||
print('wallpaper image not opened: ' + str(path))
|
||||
print(e)
|
||||
self._append(result, self._use_term(stem))
|
||||
|
||||
return result
|
||||
@@ -450,15 +448,6 @@ class Tags:
|
||||
result.append(entry)
|
||||
return sorted(result)
|
||||
|
||||
def image_aspect_ratio(path: Path) -> float:
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError as _e:
|
||||
subprocess.run([sys.executable, '-m', 'pip', 'install', 'Pillow'], stderr=subprocess.STDOUT, check=True)
|
||||
from PIL import Image
|
||||
img = Image.open(str(path))
|
||||
return float(img.width) / float(img.height)
|
||||
|
||||
class DatabaseBuilder:
|
||||
main_binaries = ['MiSTer', 'menu.rbf']
|
||||
|
||||
@@ -870,6 +859,25 @@ def _read_mgl_fields_impl(mgl_path: Path) -> Tuple[Optional[str], Optional[str]]
|
||||
|
||||
return rbf, setname
|
||||
|
||||
# Read other files
|
||||
|
||||
def read_image_aspect_ratio(path: Path) -> Optional[float]:
|
||||
try:
|
||||
_ensure_image_library()
|
||||
from PIL import Image
|
||||
img = Image.open(str(path))
|
||||
return float(img.width) / float(img.height)
|
||||
except Exception as e:
|
||||
print('wallpaper image not opened: ' + str(path))
|
||||
print(e)
|
||||
return None
|
||||
|
||||
def _ensure_image_library() -> None:
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError as _e:
|
||||
subprocess.run([sys.executable, '-m', 'pip', 'install', 'Pillow'], stderr=subprocess.STDOUT, check=True)
|
||||
|
||||
# MiSTer network utilities
|
||||
|
||||
def download_db(url: str) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user