Match photo selection and rendered canvas to device rotation

This commit is contained in:
Pigway
2026-10-05 22:44:41 +08:00
parent 8139a646d7
commit 59345f12a7
13 changed files with 249 additions and 35 deletions
+19 -6
View File
@@ -17,6 +17,7 @@ from pigway_frame_flow.models import (
URLContent,
)
from pigway_frame_flow.providers.photo_sources import PhotoSources
from pigway_frame_flow.renderers.frame_geometry import frame_canvas
from pigway_frame_flow.renderers.images import convert
from pigway_frame_flow.renderers.photo_caption import render_captioned_photo
from pigway_frame_flow.storage.database import encode, now_iso
@@ -157,7 +158,7 @@ class DisplayService:
)
return self.db.one("SELECT * FROM device_state WHERE device_id=?", (id,))
def content_asset(self, content):
def content_asset(self, content, device_id=None):
if isinstance(content, TemplateContent):
values = self.renderer.resolve(content.template, content.data)
data = self.renderer.render(content.template, values, content.profile)
@@ -174,15 +175,25 @@ class DisplayService:
)
return asset
if isinstance(content, PhotoSourceContent):
source = self.photo_sources.get(content.source_id)
display = (
self.registry.get(device_id or self.settings.device_id).device().display
)
size = frame_canvas(display, source.orientation)
data, name, caption = self.photo_sources.read(
content.source_id, content.item_id
content.source_id, content.item_id, target_size=size
)
rendered = (
render_captioned_photo(
data, caption, self.renderer.font, content.fit, content.profile
data,
caption,
self.renderer.font,
content.fit,
content.profile,
size=size,
)
if caption
else convert(data, content.fit, content.profile)
else convert(data, content.fit, content.profile, size=size)
)
return self.assets.put(rendered, name)
if isinstance(content, URLContent):
@@ -310,7 +321,9 @@ class DisplayService:
from pigway_frame_flow.models import Content
asset = self.content_asset(TypeAdapter(Content).validate_python(payload))
asset = self.content_asset(
TypeAdapter(Content).validate_python(payload), device_id
)
if action == "local-upload":
asset = self.assets.promote(asset["asset_id"])
self.update(
@@ -389,7 +402,7 @@ class DisplayService:
)
image_id = matches[0].image_id
else:
asset = self.content_asset(content)
asset = self.content_asset(content, device_id)
image_id = None
self.db.execute(
"UPDATE device_state SET previous_image_id=? WHERE device_id=?",