Apply dithering to shared item images

main
bashrc 2026-07-26 17:22:00 +01:00
parent 67427f215f
commit 3e304dca55
3 changed files with 11 additions and 7 deletions

View File

@ -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'

View File

@ -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 ' + \

View File

@ -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,