From 3e304dca5595be5257c70ff2e9fc10bebbcdeadd Mon Sep 17 00:00:00 2001 From: bashrc Date: Sun, 26 Jul 2026 17:22:00 +0100 Subject: [PATCH] Apply dithering to shared item images --- src/daemon_post_receive.py | 8 +++++--- src/media.py | 2 +- src/shares.py | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/daemon_post_receive.py b/src/daemon_post_receive.py index b7a26786a..657d2cdf3 100644 --- a/src/daemon_post_receive.py +++ b/src/daemon_post_receive.py @@ -1911,8 +1911,8 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, # Note: a .temp extension is used here so that at no time is # an image with metadata publicly exposed, even for a few mS - filename_base = \ - acct_dir(base_dir, nickname, domain) + '/upload.temp' + account_dir = acct_dir(base_dir, nickname, domain) + filename_base = account_dir + '/upload.temp' filename, attachment_media_type = \ save_media_in_form_post(media_bytes, debug, filename_base) @@ -1925,8 +1925,10 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, exif_json: list[dict] = [] if filename: if is_image_file(filename): + dither_filename = account_dir + '/.ditherImage' + apply_dithering = is_a_file(dither_filename) # convert to low bandwidth if needed - if low_bandwidth: + if low_bandwidth or apply_dithering: print('Converting to low bandwidth ' + filename) convert_image_to_low_bandwidth(filename) backup_filename = filename + '.backup' diff --git a/src/media.py b/src/media.py index 551b347f7..ced223d8d 100644 --- a/src/media.py +++ b/src/media.py @@ -496,7 +496,7 @@ def convert_image_to_low_bandwidth(image_filename: str) -> None: cmd = \ "convert \"" + safe_system_string(image_filename) + "\" " + \ - "-resize 800 -set option:distort:viewport '%wx%h+0+0' " + \ + "-resize 1000 -set option:distort:viewport '%wx%h+0+0' " + \ '-colorspace CMYK -separate null: \\( -size 2x2 xc: ' + \ '\\( +clone -negate \\) +append \\( +clone -negate \\) ' + \ '-append \\) -virtual-pixel tile -filter gaussian ' + \ diff --git a/src/shares.py b/src/shares.py index b2920c39b..c749feccc 100644 --- a/src/shares.py +++ b/src/shares.py @@ -352,8 +352,8 @@ def add_share(base_dir: str, system_language): print('Shared item was filtered due to content') return - shares_filename = \ - acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json' + account_dir = acct_dir(base_dir, nickname, domain) + shares_filename = account_dir + '/' + shares_file_type + '.json' shares_json = {} if is_a_file(shares_filename): shares_json = load_json(shares_filename) @@ -393,10 +393,12 @@ def add_share(base_dir: str, makedir(base_dir + '/sharefiles/' + nickname) item_idfile = base_dir + '/sharefiles/' + nickname + '/' + item_id formats = get_image_extensions() + dither_filename = account_dir + '/.ditherImage' + apply_dithering = is_a_file(dither_filename) for ext in formats: if not image_filename.endswith('.' + ext): continue - if low_bandwidth: + if low_bandwidth or apply_dithering: convert_image_to_low_bandwidth(image_filename) exif_json: list[dict] = [] process_meta_data(base_dir, nickname, domain,