diff --git a/daemon.py b/daemon.py index f76d5664b..90c672f1b 100644 --- a/daemon.py +++ b/daemon.py @@ -760,7 +760,8 @@ def run_daemon(accounts_data_dir: str, send_threads: [], manual_follower_approval: bool, watermark_width_percent: int, - watermark_position: str) -> None: + watermark_position: str, + watermark_opacity: int) -> None: if len(domain) == 0: domain = 'localhost' if '.' not in domain: @@ -804,10 +805,11 @@ def run_daemon(accounts_data_dir: str, httpd.starting_daemon = True - # width of watermark applied to attached images + # width, position and opacity of watermark applied to attached images # as a percentage of the attached image width httpd.watermark_width_percent = watermark_width_percent httpd.watermark_position = watermark_position + httpd.watermark_opacity = watermark_opacity # for each account whether to hide announces httpd.hide_announces = {} diff --git a/daemon_post.py b/daemon_post.py index d053990e4..579152b8f 100644 --- a/daemon_post.py +++ b/daemon_post.py @@ -869,7 +869,8 @@ def daemon_http_post(self) -> None: self.server.i2p_domain, self.server.max_shares_on_profile, self.server.watermark_width_percent, - self.server.watermark_position) + self.server.watermark_position, + self.server.watermark_opacity) if page_number: print(curr_post_type + ' post received') nickname = self.path.split('/users/')[1] diff --git a/daemon_post_receive.py b/daemon_post_receive.py index 7f45ff0ce..80a3626b3 100644 --- a/daemon_post_receive.py +++ b/daemon_post_receive.py @@ -1597,7 +1597,8 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, i2p_domain: str, max_shares_on_profile: int, watermark_width_percent: int, - watermark_position: str) -> int: + watermark_position: str, + watermark_opacity: int) -> int: # Note: this needs to happen synchronously # 0=this is not a new post # 1=new post success @@ -1691,7 +1692,8 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, convert_image_to_low_bandwidth(filename) apply_watermark_to_image(base_dir, nickname, domain, filename, watermark_width_percent, - watermark_position) + watermark_position, + watermark_opacity) post_image_filename = filename.replace('.temp', '') print('Removing metadata from ' + post_image_filename) city = get_spoofed_city(city, base_dir, nickname, domain) @@ -2200,7 +2202,8 @@ def receive_new_post(self, post_type, path: str, i2p_domain: str, max_shares_on_profile: int, watermark_width_percent: int, - watermark_position: str) -> int: + watermark_position: str, + watermark_opacity: int) -> int: """A new post has been created This creates a thread to send the new post """ @@ -2340,7 +2343,8 @@ def receive_new_post(self, post_type, path: str, i2p_domain, max_shares_on_profile, watermark_width_percent, - watermark_position) + watermark_position, + watermark_opacity) if debug: print('DEBUG: _receive_new_post_process returned ' + str(retval)) diff --git a/epicyon.py b/epicyon.py index 8dabaae66..2be30a466 100644 --- a/epicyon.py +++ b/epicyon.py @@ -256,6 +256,10 @@ def _command_options() -> None: default=30, help='Width of the watermark applied to attached ' + 'images as a percentage of the attached image width') + parser.add_argument('--watermarkOpacity', + dest='watermark_opacity', type=int, + default=10, + help='Opacity of watermark applied to attached images') parser.add_argument('--watermarkPosition', dest='watermark_position', type=str, default="east", @@ -3878,6 +3882,15 @@ def _command_options() -> None: 'southeast', 'southwest'): argb.watermark_position = 'east' + watermark_opacity = \ + get_config_param(base_dir, 'watermarkOpacity') + if watermark_opacity is not None: + argb.watermark_opacity = int(watermark_opacity) + if argb.watermark_opacity < 0: + argb.watermark_opacity = 0 + if argb.watermark_opacity > 100: + argb.watermark_opacity = 100 + show_publish_as_icon = \ get_config_param(base_dir, 'showPublishAsIcon') if show_publish_as_icon is not None: @@ -4111,4 +4124,5 @@ if __name__ == "__main__": argb2.instance_only_skills_search, [], not argb2.noapproval, argb2.watermark_width_percent, - argb2.watermark_position) + argb2.watermark_position, + argb2.watermark_opacity) diff --git a/media.py b/media.py index 2016a37e8..24b73aff4 100644 --- a/media.py +++ b/media.py @@ -766,7 +766,8 @@ def get_image_dimensions(image_filename: str) -> (int, int): def apply_watermark_to_image(base_dir: str, nickname: str, domain: str, post_image_filename: str, watermark_width_percent: int, - watermark_position: str) -> bool: + watermark_position: str, + watermark_opacity: int) -> bool: """Applies a watermark to the given image """ if not os.path.isfile(post_image_filename): @@ -800,11 +801,17 @@ def apply_watermark_to_image(base_dir: str, nickname: str, domain: str, 'southeast', 'southwest'): watermark_position = 'east' + if watermark_opacity < 0: + watermark_opacity = 0 + if watermark_opacity > 100: + watermark_opacity = 100 + cmd = \ '/usr/bin/composite ' + \ '-geometry ' + str(scaled_watermark_image_width) + 'x' + \ str(scaled_watermark_image_height) + '+30+5 ' + \ - '-watermark 10% -gravity ' + watermark_position + ' ' + \ + '-watermark ' + str(watermark_opacity) + '% ' + \ + '-gravity ' + watermark_position + ' ' + \ safe_system_string(watermark_filename) + ' ' + \ safe_system_string(post_image_filename) + ' ' + \ safe_system_string(post_image_filename + '.watermarked') diff --git a/tests.py b/tests.py index e2f51e01f..163e6c78f 100644 --- a/tests.py +++ b/tests.py @@ -895,6 +895,7 @@ def create_server_alice(path: str, domain: str, port: int, accounts_data_dir = None watermark_width_percent = 30 watermark_position = 'east' + watermark_opacity = 10 print('Server running: Alice') run_daemon(accounts_data_dir, no_of_books, public_replies_unlisted, @@ -927,7 +928,7 @@ def create_server_alice(path: str, domain: str, port: int, domain_max_posts_per_day, account_max_posts_per_day, allow_deletion, True, True, False, send_threads, False, watermark_width_percent, - watermark_position) + watermark_position, watermark_opacity) def create_server_bob(path: str, domain: str, port: int, @@ -1084,6 +1085,7 @@ def create_server_bob(path: str, domain: str, port: int, accounts_data_dir = None watermark_width_percent = 30 watermark_position = 'east' + watermark_opacity = 10 print('Server running: Bob') run_daemon(accounts_data_dir, no_of_books, public_replies_unlisted, @@ -1116,7 +1118,7 @@ def create_server_bob(path: str, domain: str, port: int, domain_max_posts_per_day, account_max_posts_per_day, allow_deletion, True, True, False, send_threads, False, watermark_width_percent, - watermark_position) + watermark_position, watermark_opacity) def create_server_eve(path: str, domain: str, port: int, federation_list: [], @@ -1181,6 +1183,7 @@ def create_server_eve(path: str, domain: str, port: int, federation_list: [], accounts_data_dir = None watermark_width_percent = 30 watermark_position = 'east' + watermark_opacity = 10 print('Server running: Eve') run_daemon(accounts_data_dir, no_of_books, public_replies_unlisted, @@ -1234,7 +1237,8 @@ def create_server_eve(path: str, domain: str, port: int, federation_list: [], True, True, False, send_threads, False, watermark_width_percent, - watermark_position) + watermark_position, + watermark_opacity) def create_server_group(path: str, domain: str, port: int, @@ -1301,6 +1305,7 @@ def create_server_group(path: str, domain: str, port: int, accounts_data_dir = None watermark_width_percent = 30 watermark_position = 'east' + watermark_opacity = 10 print('Server running: Group') run_daemon(accounts_data_dir, no_of_books, public_replies_unlisted, @@ -1333,7 +1338,7 @@ def create_server_group(path: str, domain: str, port: int, domain_max_posts_per_day, account_max_posts_per_day, allow_deletion, True, True, False, send_threads, False, watermark_width_percent, - watermark_position) + watermark_position, watermark_opacity) def test_post_message_between_servers(base_dir: str) -> None: