From 7a9778393af38e5b811a7f8612fe034347ff7fb4 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Wed, 23 Nov 2022 23:09:16 -0700 Subject: [PATCH] Screenshot: Add --quality to edit subcommand --- bin/screenshot_wayland.py | 19 ++++++++++++++----- sway/config | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/bin/screenshot_wayland.py b/bin/screenshot_wayland.py index 6475248..6161cd4 100755 --- a/bin/screenshot_wayland.py +++ b/bin/screenshot_wayland.py @@ -26,7 +26,8 @@ DS_SHADOW_LIGHT = 'black' DS_BG_DARK = '#d3869b' DS_SHADOW_DARK = 'black' -EDIT_QUALITY = 50 +DEFAULT_EDIT_QUALITY = 50 +DEFAULT_EDIT_EXTENSION = 'avif' # Returns the path of the latest screenshot def get_latest_sceenshot_path() -> Path: @@ -126,7 +127,9 @@ def take_subcommand(args): # Applies an edit to the latest screenshot def edit_subcommand(args): - ext = args.extension if args.extension else 'avif' + ext = args.extension if args.extension else DEFAULT_EDIT_EXTENSION + quality = args.quality if args.quality is not None else DEFAULT_EDIT_QUALITY + og_path, edit_path = get_edit_path(ext) if args.overwrite: @@ -145,7 +148,7 @@ def edit_subcommand(args): img = img.resize(args.size) elif args.rescale: img = img.reduce(int(1 / (args.rescale / 100))) - img.save(edit_path, quality=EDIT_QUALITY, method=6) + img.save(edit_path, quality=quality, method=6) if args.clipboard: copy_to_clipboard(edit_path) @@ -252,7 +255,7 @@ edit_subcmd = subcommands.add_parser( edit_subcmd.add_argument( '-r', '--rescale', type=parse_percent, - metavar="", + metavar="", help='Rescale the latest screenshot to of the original', ); edit_subcmd.add_argument( @@ -278,6 +281,12 @@ edit_subcmd.add_argument( metavar="", help='Change image extension and image type saved', ); +edit_subcmd.add_argument( + '-q', '--quality', + type=parse_percent, + metavar='', + help='Set quality of new image. [0, 100], higher means bigger file', +); edit_subcmd.add_argument( '--overwrite', action='store_true', @@ -285,7 +294,7 @@ edit_subcmd.add_argument( ); edit_subcmd.add_argument( "file", nargs='?', type=Path, - help="Save the screenshot to this file name" + help="Save the edited screenshot to this file name" ); # Markup ==== markup_subcmd = subcommands.add_parser( diff --git a/sway/config b/sway/config index dc6e04a..763ab16 100644 --- a/sway/config +++ b/sway/config @@ -298,7 +298,7 @@ bindsym $mod2+Escape exec ~/.config/sway/sway_exit.sh bindsym $mod2+6 mode "screenshots" bindsym $mod2+5 mode "screenshots"; exec $screenshot_script take select -c $screenshot_tmp && $screenshot_sound bindsym $mod2+4 mode "screenshots"; exec $screenshot_script take exact "$(~/.config/sway/window_dimensions.py)" && \ - $screenshot_script edit -c --overwrite -d "$(colo.sh -t)" -e png $screenshot_tmp && $screenshot_sound + $screenshot_script edit -c -q 100 -d "$(colo.sh -t)" -e png --overwrite $screenshot_tmp && $screenshot_sound mode "screenshots" { # Screenshooting in processing "steps"