Skip to content

Commit

Permalink
fix(python): increase homescreen quality when uploading via trezorctl
Browse files Browse the repository at this point in the history
fixes #3893
  • Loading branch information
matejcik committed Jun 20, 2024
1 parent aab2eaf commit 1789a43
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions python/.changelog.d/3893.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `--quality` argument to `trezorctl set homescreen`.
1 change: 1 addition & 0 deletions python/.changelog.d/3893.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increased default JPEG quality for uploaded homescreen.
9 changes: 5 additions & 4 deletions python/src/trezorlib/cli/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def image_to_toif(filename: Path, width: int, height: int, greyscale: bool) -> b
return toif_image.to_bytes()


def image_to_jpeg(filename: Path, width: int, height: int) -> bytes:
def image_to_jpeg(filename: Path, width: int, height: int, quality: int = 90) -> bytes:
if filename.suffix in (".jpg", ".jpeg") and not PIL_AVAILABLE:
click.echo("Warning: Image library is missing, skipping image validation.")
return filename.read_bytes()
Expand Down Expand Up @@ -147,7 +147,7 @@ def image_to_jpeg(filename: Path, width: int, height: int) -> bytes:
image = image.convert("RGB")

buf = io.BytesIO()
image.save(buf, format="jpeg", progressive=False)
image.save(buf, format="jpeg", progressive=False, quality=quality)
return buf.getvalue()


Expand Down Expand Up @@ -307,8 +307,9 @@ def flags(client: "TrezorClient", flags: str) -> str:
@click.option(
"-f", "--filename", "_ignore", is_flag=True, hidden=True, expose_value=False
)
@click.option("-q", "--quality", type=int, default=90, help="JPEG quality (0-100)")
@with_client
def homescreen(client: "TrezorClient", filename: str) -> str:
def homescreen(client: "TrezorClient", filename: str, quality: int) -> str:
"""Set new homescreen.
To revert to default homescreen, use 'trezorctl set homescreen default'
Expand All @@ -334,7 +335,7 @@ def homescreen(client: "TrezorClient", filename: str) -> str:
if client.features.homescreen_height is not None
else 240
)
img = image_to_jpeg(path, width, height)
img = image_to_jpeg(path, width, height, quality)
elif client.features.homescreen_format == messages.HomescreenFormat.ToiG:
width = client.features.homescreen_width
height = client.features.homescreen_height
Expand Down

0 comments on commit 1789a43

Please sign in to comment.