Option to add watermark to uploaded images

main
Bob Mottram 2024-07-22 18:27:21 +01:00
parent 0fdcadd825
commit 149dcd72cb
34 changed files with 134 additions and 34 deletions

View File

@ -2490,8 +2490,8 @@ def daemon_http_get(self) -> None:
'_GET', 'account qrcode done',
self.server.debug)
# search screen banner image
if users_in_path:
# search screen banner image
if self.path.endswith('/search_banner.png'):
if search_screen_banner(self, self.path,
self.server.base_dir,
@ -2502,6 +2502,7 @@ def daemon_http_get(self) -> None:
self.server.debug):
return
# main timeline left column
if self.path.endswith('/left_col_image.png'):
if column_image(self, 'left', self.path,
self.server.base_dir,
@ -2512,6 +2513,7 @@ def daemon_http_get(self) -> None:
self.server.debug):
return
# main timeline right column
if self.path.endswith('/right_col_image.png'):
if column_image(self, 'right', self.path,
self.server.base_dir,
@ -2522,6 +2524,11 @@ 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

@ -72,6 +72,8 @@ def show_avatar_or_banner(self, referer_domain: str, path: str,
avatar_file = 'left_col_image.' + avatar_file_ext
elif avatar_file.startswith('right_col_image'):
avatar_file = 'right_col_image.' + avatar_file_ext
elif avatar_file.startswith('watermark_image'):
avatar_file = 'watermark_image.' + avatar_file_ext
avatar_filename = \
acct_dir(base_dir, avatar_nickname, domain) + '/' + avatar_file
if not os.path.isfile(avatar_filename):

View File

@ -2541,6 +2541,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
'banner', 'search_banner',
'instanceLogo',
'left_col_image', 'right_col_image',
'watermark_image',
'importFollows',
'importTheme'
)

View File

@ -11,6 +11,7 @@ import os
import time
import copy
import errno
import subprocess
from socket import error as SocketError
from shares import add_share
from languages import get_understood_languages
@ -27,6 +28,7 @@ from media import process_meta_data
from media import convert_image_to_low_bandwidth
from media import attach_media
from city import get_spoofed_city
from utils import safe_system_string
from utils import get_instance_url
from utils import is_float
from utils import save_json
@ -53,6 +55,7 @@ from inbox import populate_replies
from inbox import update_edited_post
from daemon_utils import post_to_outbox
from webapp_column_right import html_citations
from webapp_utils import get_watermark_file
from httpheaders import set_headers
from httpcodes import write2
from cache import store_person_in_cache
@ -66,6 +69,44 @@ NEW_POST_FAILED = -1
NEW_POST_CANCELLED = 2
def _apply_watermark_to_image(base_dir: str, nickname: str, domain: str,
post_image_filename: str) -> bool:
"""Applies a watermark to the given image
"""
if not os.path.isfile(post_image_filename):
return False
if not os.path.isfile('/usr/bin/composite'):
return False
_, watermark_filename = get_watermark_file(base_dir, nickname, domain)
if not watermark_filename:
return False
if not os.path.isfile(watermark_filename):
return False
cmd = \
'/usr/bin/composite -watermark 75% -gravity east ' + \
safe_system_string(watermark_filename) + ' ' + \
safe_system_string(post_image_filename) + ' ' + \
safe_system_string(post_image_filename + '.watermarked')
subprocess.call(cmd, shell=True)
if not os.path.isfile(post_image_filename + '.watermarked'):
return False
try:
os.remove(post_image_filename)
except OSError:
print('EX: _apply_watermark_to_image unable to remove ' +
post_image_filename)
return False
try:
os.rename(post_image_filename + '.watermarked', post_image_filename)
except OSError:
print('EX: _apply_watermark_to_image unable to rename ' +
post_image_filename + '.watermarked')
return False
return True
def _receive_new_post_process_newpost(self, fields: {},
base_dir: str, nickname: str,
domain: str, domain_full: str, port: int,
@ -1683,13 +1724,17 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
if filename:
if is_image_file(filename):
post_image_filename = filename.replace('.temp', '')
# convert to low bandwidth if needed
if low_bandwidth:
print('Converting to low bandwidth ' + filename)
convert_image_to_low_bandwidth(filename)
print('Removing metadata from ' + post_image_filename)
city = get_spoofed_city(city, base_dir, nickname, domain)
if low_bandwidth:
convert_image_to_low_bandwidth(filename)
process_meta_data(base_dir, nickname, domain,
filename, post_image_filename, city,
content_license_url)
_apply_watermark_to_image(base_dir, nickname, domain,
post_image_filename)
if os.path.isfile(post_image_filename):
print('POST media saved to ' + post_image_filename)
else:

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "التخلي عن الرسالة المباشرة الجديدة",
"Press Enter to continue": "إضغط مفتاح الدخول للاستمرار",
"PGP Public Key": "مفتاح PGP العام",
"Don't show already seen posts": "لا تظهر المشاركات التي تمت مشاهدتها بالفعل"
"Don't show already seen posts": "لا تظهر المشاركات التي تمت مشاهدتها بالفعل",
"Watermark image": "صورة العلامة المائية"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "নতুন সরাসরি বার্তা পরিত্যাগ",
"Press Enter to continue": "চালিয়ে যেতে এন্টার টিপুন",
"PGP Public Key": "PGP পাবলিক কী",
"Don't show already seen posts": "ইতিমধ্যে দেখা পোস্ট দেখাবেন না"
"Don't show already seen posts": "ইতিমধ্যে দেখা পোস্ট দেখাবেন না",
"Watermark image": "ওয়াটারমার্ক ইমেজ"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "S'abandona el nou missatge directe",
"Press Enter to continue": "Premeu Intro per continuar",
"PGP Public Key": "Clau pública PGP",
"Don't show already seen posts": "No mostris les publicacions ja vistes"
"Don't show already seen posts": "No mostris les publicacions ja vistes",
"Watermark image": "Imatge de filigrana"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Rhoi'r gorau i neges uniongyrchol newydd",
"Press Enter to continue": "Pwyswch Enter i barhau",
"PGP Public Key": "Allwedd Gyhoeddus PGP",
"Don't show already seen posts": "Peidiwch â dangos postiadau a welwyd eisoes"
"Don't show already seen posts": "Peidiwch â dangos postiadau a welwyd eisoes",
"Watermark image": "Delwedd dyfrnod"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Neue Direktnachricht abbrechen",
"Press Enter to continue": "Drücken Sie die Eingabetaste, um fortzufahren",
"PGP Public Key": "Öffentlicher PGP-Schlüssel",
"Don't show already seen posts": "Bereits gesehene Beiträge nicht anzeigen"
"Don't show already seen posts": "Bereits gesehene Beiträge nicht anzeigen",
"Watermark image": "Wasserzeichenbild"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Εγκατάλειψη νέου άμεσου μηνύματος",
"Press Enter to continue": "Πατήστε Enter για να συνεχίσετε",
"PGP Public Key": "Δημόσιο κλειδί PGP",
"Don't show already seen posts": "Να μην εμφανίζονται οι αναρτήσεις που έχετε ήδη δει"
"Don't show already seen posts": "Να μην εμφανίζονται οι αναρτήσεις που έχετε ήδη δει",
"Watermark image": "Εικόνα υδατογραφήματος"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Abandoning new direct message",
"Press Enter to continue": "Press Enter to continue",
"PGP Public Key": "PGP Public Key",
"Don't show already seen posts": "Don't show already seen posts"
"Don't show already seen posts": "Don't show already seen posts",
"Watermark image": "Watermark image"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Abandonar nuevo mensaje directo",
"Press Enter to continue": "Presione Entrar para continuar",
"PGP Public Key": "Clave pública PGP",
"Don't show already seen posts": "No mostrar publicaciones ya vistas"
"Don't show already seen posts": "No mostrar publicaciones ya vistas",
"Watermark image": "Imagen de marca de agua"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "رها کردن پیام مستقیم جدید",
"Press Enter to continue": "برای ادامه Enter را فشار دهید",
"PGP Public Key": "کلید عمومی PGP",
"Don't show already seen posts": "پست های قبلا دیده شده را نشان ندهید"
"Don't show already seen posts": "پست های قبلا دیده شده را نشان ندهید",
"Watermark image": "تصویر واترمارک"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Uuden suoran viestin hylkääminen",
"Press Enter to continue": "Jatka painamalla Enter",
"PGP Public Key": "PGP julkinen avain",
"Don't show already seen posts": "Älä näytä jo nähtyjä viestejä"
"Don't show already seen posts": "Älä näytä jo nähtyjä viestejä",
"Watermark image": "Vesileiman kuva"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Abandonner un nouveau message direct",
"Press Enter to continue": "Appuyez sur Entrée pour continuer",
"PGP Public Key": "Clé publique PGP",
"Don't show already seen posts": "Ne pas afficher les messages déjà vus"
"Don't show already seen posts": "Ne pas afficher les messages déjà vus",
"Watermark image": "Image en filigrane"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Teachtaireacht dhíreach nua a thréigean",
"Press Enter to continue": "Brúigh Enter chun leanúint ar aghaidh",
"PGP Public Key": "Eochair Phoiblí PGP",
"Don't show already seen posts": "Ná taispeáin postálacha atá feicthe cheana féin"
"Don't show already seen posts": "Ná taispeáin postálacha atá feicthe cheana féin",
"Watermark image": "Íomhá comhartha uisce"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "נטישת הודעה ישירה חדשה",
"Press Enter to continue": "לחץ על Enter כדי להמשיך",
"PGP Public Key": "מפתח PGP ציבורי",
"Don't show already seen posts": "אל תראה פוסטים שכבר נראו"
"Don't show already seen posts": "אל תראה פוסטים שכבר נראו",
"Watermark image": "תמונת סימן מים"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "नए प्रत्यक्ष संदेश का परित्याग",
"Press Enter to continue": "जारी रखने के लिए Enter दबाएँ",
"PGP Public Key": "पीजीपी सार्वजनिक कुंजी",
"Don't show already seen posts": "पहले से देखी गई पोस्ट न दिखाएं"
"Don't show already seen posts": "पहले से देखी गई पोस्ट न दिखाएं",
"Watermark image": "वॉटरमार्क छवि"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Abbandonare il nuovo messaggio diretto",
"Press Enter to continue": "Premere Invio per continuare",
"PGP Public Key": "Chiave pubblica PGP",
"Don't show already seen posts": "Non mostrare i post già visti"
"Don't show already seen posts": "Non mostrare i post già visti",
"Watermark image": "Immagine filigrana"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "新しいダイレクトメッセージの放棄",
"Press Enter to continue": "続行するには Enter キーを押してください",
"PGP Public Key": "PGP公開鍵",
"Don't show already seen posts": "すでに閲覧した投稿を表示しない"
"Don't show already seen posts": "すでに閲覧した投稿を表示しない",
"Watermark image": "透かし画像"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "새 다이렉트 메시지 포기하기",
"Press Enter to continue": "계속하려면 Enter를 누르세요.",
"PGP Public Key": "PGP 공개 키",
"Don't show already seen posts": "이미 본 게시물을 표시하지 않음"
"Don't show already seen posts": "이미 본 게시물을 표시하지 않음",
"Watermark image": "워터마크 이미지"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Rakirina peyama rasterast a nû",
"Press Enter to continue": "Ji bo berdewamkirinê Enter bikirtînin",
"PGP Public Key": "Mifteya Giştî ya PGP",
"Don't show already seen posts": "Mesajên ku berê hatine dîtin nîşan nedin"
"Don't show already seen posts": "Mesajên ku berê hatine dîtin nîşan nedin",
"Watermark image": "Wêneyê Watermark"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Nieuw privéchat verlaten",
"Press Enter to continue": "Druk op Enter om door te gaan",
"PGP Public Key": "PGP publieke sleutel",
"Don't show already seen posts": "Toon geen reeds bekeken berichten"
"Don't show already seen posts": "Toon geen reeds bekeken berichten",
"Watermark image": "Watermerk afbeelding"
}

View File

@ -690,5 +690,6 @@
"Abandoning new direct message": "Abandoning new direct message",
"Press Enter to continue": "Press Enter to continue",
"PGP Public Key": "PGP Public Key",
"Don't show already seen posts": "Don't show already seen posts"
"Don't show already seen posts": "Don't show already seen posts",
"Watermark image": "Watermark image"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Porzucenie nowej wiadomości bezpośredniej",
"Press Enter to continue": "Naciśnij Enter, aby kontynuować",
"PGP Public Key": "Klucz publiczny PGP",
"Don't show already seen posts": "Nie pokazuj już wyświetlonych postów"
"Don't show already seen posts": "Nie pokazuj już wyświetlonych postów",
"Watermark image": "Obraz znaku wodnego"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Abandonando nova mensagem direta",
"Press Enter to continue": "Pressione Enter para continuar",
"PGP Public Key": "Chave pública PGP",
"Don't show already seen posts": "Não mostrar posts já vistos"
"Don't show already seen posts": "Não mostrar posts já vistos",
"Watermark image": "Imagem de marca de água"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Отказ от нового прямого сообщения",
"Press Enter to continue": "Нажмите Enter, чтобы продолжить",
"PGP Public Key": "Открытый ключ PGP",
"Don't show already seen posts": "Не показывать уже просмотренные публикации"
"Don't show already seen posts": "Не показывать уже просмотренные публикации",
"Watermark image": "Изображение водяного знака"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Kuacha ujumbe mpya wa moja kwa moja",
"Press Enter to continue": "Bonyeza Enter ili kuendelea",
"PGP Public Key": "Ufunguo wa Umma wa PGP",
"Don't show already seen posts": "Usionyeshe machapisho ambayo tayari yameonekana"
"Don't show already seen posts": "Usionyeshe machapisho ambayo tayari yameonekana",
"Watermark image": "Picha ya watermark"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Yeni doğrudan mesajdan vazgeçiliyor",
"Press Enter to continue": "Devam etmek için Enter'a basın",
"PGP Public Key": "PGP Genel Anahtarı",
"Don't show already seen posts": "Daha önce görülen gönderileri gösterme"
"Don't show already seen posts": "Daha önce görülen gönderileri gösterme",
"Watermark image": "Filigran resmi"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "Відмова від нового прямого повідомлення",
"Press Enter to continue": "Натисніть Enter, щоб продовжити",
"PGP Public Key": "Відкритий ключ PGP",
"Don't show already seen posts": "Не показувати вже переглянуті публікації"
"Don't show already seen posts": "Не показувати вже переглянуті публікації",
"Watermark image": "Зображення водяного знака"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "פארלאזן נייַ דירעקט אָנזאָג",
"Press Enter to continue": "דרוק אַרייַן צו פאָרזעצן",
"PGP Public Key": "PGP ציבור שליסל",
"Don't show already seen posts": "צי ניט ווייַזן שוין געזען אַרטיקלען"
"Don't show already seen posts": "צי ניט ווייַזן שוין געזען אַרטיקלען",
"Watermark image": "וואָטערמאַרק בילד"
}

View File

@ -694,5 +694,6 @@
"Abandoning new direct message": "放弃新的私信",
"Press Enter to continue": "按 Enter 继续",
"PGP Public Key": "PGP 公钥",
"Don't show already seen posts": "不显示已经看过的帖子"
"Don't show already seen posts": "不显示已经看过的帖子",
"Watermark image": "水印图像"
}

View File

@ -2674,6 +2674,11 @@ def _html_edit_profile_background(news_instance: bool, translate: {}) -> str:
translate['Right column image'] + '</label>\n' + \
' <input type="file" id="right_col_image" ' + \
'name="right_col_image"' + \
' accept="' + image_formats + '">\n' + \
' <br><label class="labels">' + \
translate['Watermark image'] + '</label>\n' + \
' <input type="file" id="watermark_image" ' + \
'name="watermark_image"' + \
' accept="' + image_formats + '">\n'
edit_profile_form += end_edit_section()

View File

@ -660,13 +660,15 @@ def _get_image_file(base_dir: str, name: str, directory: str,
banner_filename = banner_filename_test
return banner_file, banner_filename
# if not found then use the default image
theme = 'default'
directory = base_dir + '/theme/' + theme
curr_theme = 'default'
if theme:
curr_theme = theme
directory = base_dir + '/theme/' + curr_theme
for ext in banner_extensions:
banner_file_test = name + '.' + ext
banner_filename_test = directory + '/' + banner_file_test
if os.path.isfile(banner_filename_test):
banner_file = name + '_' + theme + '.' + ext
banner_file = name + '_' + curr_theme + '.' + ext
banner_filename = banner_filename_test
break
return banner_file, banner_filename
@ -724,6 +726,16 @@ def get_right_image_file(base_dir: str,
return banner_file, banner_filename
def get_watermark_file(base_dir: str,
nickname: str, domain: str) -> (str, str):
"""Gets the filename for watermarking when an image is attached to a post
"""
account_dir = acct_dir(base_dir, nickname, domain)
watermark_file, watermark_filename = \
_get_image_file(base_dir, 'watermark_image', account_dir, '')
return watermark_file, watermark_filename
def html_header_with_external_style(css_filename: str, instance_title: str,
metadata: str, lang='en') -> str:
if metadata is None: