Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): increase homescreen quality when uploading via trezorctl #3945

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading