Option to set watermark position

main
Bob Mottram 2024-07-25 14:53:15 +01:00
parent 98ad4609b4
commit b70ae582d9
7 changed files with 55 additions and 22 deletions

View File

@ -759,7 +759,8 @@ def run_daemon(accounts_data_dir: str,
instance_only_skills_search: bool,
send_threads: [],
manual_follower_approval: bool,
watermark_width_percent: int) -> None:
watermark_width_percent: int,
watermark_position: str) -> None:
if len(domain) == 0:
domain = 'localhost'
if '.' not in domain:
@ -806,6 +807,7 @@ def run_daemon(accounts_data_dir: str,
# width 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
# for each account whether to hide announces
httpd.hide_announces = {}

View File

@ -2524,11 +2524,6 @@ def daemon_http_get(self) -> None:
self.server.debug):
return
# watermark for image uploads/attachments
if self.path.endswith('/watermark_image.png'):
# TODO
return
fitness_performance(getreq_start_time, self.server.fitness,
'_GET', 'search screen banner done',
self.server.debug)

View File

@ -868,7 +868,8 @@ def daemon_http_post(self) -> None:
self.server.onion_domain,
self.server.i2p_domain,
self.server.max_shares_on_profile,
self.server.watermark_width_percent)
self.server.watermark_width_percent,
self.server.watermark_position)
if page_number:
print(curr_post_type + ' post received')
nickname = self.path.split('/users/')[1]

View File

@ -1596,7 +1596,8 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
onion_domain: str,
i2p_domain: str,
max_shares_on_profile: int,
watermark_width_percent: int) -> int:
watermark_width_percent: int,
watermark_position: str) -> int:
# Note: this needs to happen synchronously
# 0=this is not a new post
# 1=new post success
@ -1689,7 +1690,8 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
print('Converting to low bandwidth ' + filename)
convert_image_to_low_bandwidth(filename)
apply_watermark_to_image(base_dir, nickname, domain,
filename, watermark_width_percent)
filename, watermark_width_percent,
watermark_position)
post_image_filename = filename.replace('.temp', '')
print('Removing metadata from ' + post_image_filename)
city = get_spoofed_city(city, base_dir, nickname, domain)
@ -2197,7 +2199,8 @@ def receive_new_post(self, post_type, path: str,
onion_domain: str,
i2p_domain: str,
max_shares_on_profile: int,
watermark_width_percent: int) -> int:
watermark_width_percent: int,
watermark_position: str) -> int:
"""A new post has been created
This creates a thread to send the new post
"""
@ -2336,7 +2339,8 @@ def receive_new_post(self, post_type, path: str,
onion_domain,
i2p_domain,
max_shares_on_profile,
watermark_width_percent)
watermark_width_percent,
watermark_position)
if debug:
print('DEBUG: _receive_new_post_process returned ' +
str(retval))

View File

@ -256,6 +256,11 @@ 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('--watermarkPosition',
dest='watermark_position', type=str,
default="east",
help='Position of image watermarks ' +
'north/south/east/west')
parser.add_argument('--check-actor-timeout', dest='check_actor_timeout',
type=int, default=2,
help='Timeout in seconds used for checking is ' +
@ -3863,6 +3868,16 @@ def _command_options() -> None:
if argb.watermark_width_percent > 100:
argb.watermark_width_percent = 100
watermark_position = \
get_config_param(base_dir, 'watermarkPosition')
if watermark_position is not None:
argb.watermark_position = watermark_width_percent
if argb.watermark_position.lower() not in ('north', 'south',
'east', 'west',
'northeast', 'northwest',
'southeast', 'southwest'):
argb.watermark_position = 'east'
show_publish_as_icon = \
get_config_param(base_dir, 'showPublishAsIcon')
if show_publish_as_icon is not None:
@ -4095,4 +4110,5 @@ if __name__ == "__main__":
argb2.allowdeletion, opt2['debug'], False,
argb2.instance_only_skills_search, [],
not argb2.noapproval,
argb2.watermark_width_percent)
argb2.watermark_width_percent,
argb2.watermark_position)

View File

@ -765,7 +765,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) -> bool:
watermark_width_percent: int,
watermark_position: str) -> bool:
"""Applies a watermark to the given image
"""
if not os.path.isfile(post_image_filename):
@ -789,11 +790,17 @@ def apply_watermark_to_image(base_dir: str, nickname: str, domain: str,
int(watermark_image_height *
scaled_watermark_image_width / watermark_image_width)
if watermark_position.lower() not in ('north', 'south',
'east', 'west',
'northeast', 'northwest',
'southeast', 'southwest'):
watermark_position = 'east'
cmd = \
'/usr/bin/composite ' + \
'-geometry ' + str(scaled_watermark_image_width) + 'x' + \
str(scaled_watermark_image_height) + '+30+5 ' + \
'-watermark 10% -gravity east ' + \
'-watermark 10% -gravity ' + watermark_position + ' ' + \
safe_system_string(watermark_filename) + ' ' + \
safe_system_string(post_image_filename) + ' ' + \
safe_system_string(post_image_filename + '.watermarked')

View File

@ -893,7 +893,8 @@ def create_server_alice(path: str, domain: str, port: int,
public_replies_unlisted = False
no_of_books = 10
accounts_data_dir = None
watermark_width_percent = 20
watermark_width_percent = 30
watermark_position = 'east'
print('Server running: Alice')
run_daemon(accounts_data_dir,
no_of_books, public_replies_unlisted,
@ -925,7 +926,8 @@ def create_server_alice(path: str, domain: str, port: int,
proxy_type, max_replies,
domain_max_posts_per_day, account_max_posts_per_day,
allow_deletion, True, True, False, send_threads,
False, watermark_width_percent)
False, watermark_width_percent,
watermark_position)
def create_server_bob(path: str, domain: str, port: int,
@ -1080,7 +1082,8 @@ def create_server_bob(path: str, domain: str, port: int,
public_replies_unlisted = False
no_of_books = 10
accounts_data_dir = None
watermark_width_percent = 20
watermark_width_percent = 30
watermark_position = 'east'
print('Server running: Bob')
run_daemon(accounts_data_dir,
no_of_books, public_replies_unlisted,
@ -1112,7 +1115,8 @@ def create_server_bob(path: str, domain: str, port: int,
proxy_type, max_replies,
domain_max_posts_per_day, account_max_posts_per_day,
allow_deletion, True, True, False, send_threads,
False, watermark_width_percent)
False, watermark_width_percent,
watermark_position)
def create_server_eve(path: str, domain: str, port: int, federation_list: [],
@ -1175,7 +1179,8 @@ def create_server_eve(path: str, domain: str, port: int, federation_list: [],
domain_max_posts_per_day = 1000
account_max_posts_per_day = 1000
accounts_data_dir = None
watermark_width_percent = 20
watermark_width_percent = 30
watermark_position = 'east'
print('Server running: Eve')
run_daemon(accounts_data_dir, no_of_books,
public_replies_unlisted,
@ -1228,7 +1233,8 @@ def create_server_eve(path: str, domain: str, port: int, federation_list: [],
allow_deletion,
True, True, False,
send_threads, False,
watermark_width_percent)
watermark_width_percent,
watermark_position)
def create_server_group(path: str, domain: str, port: int,
@ -1293,7 +1299,8 @@ def create_server_group(path: str, domain: str, port: int,
public_replies_unlisted = False
no_of_books = 10
accounts_data_dir = None
watermark_width_percent = 20
watermark_width_percent = 30
watermark_position = 'east'
print('Server running: Group')
run_daemon(accounts_data_dir,
no_of_books, public_replies_unlisted,
@ -1325,7 +1332,8 @@ def create_server_group(path: str, domain: str, port: int,
proxy_type, max_replies,
domain_max_posts_per_day, account_max_posts_per_day,
allow_deletion, True, True, False, send_threads,
False, watermark_width_percent)
False, watermark_width_percent,
watermark_position)
def test_post_message_between_servers(base_dir: str) -> None: