Support for svg format images

merge-requests/30/head
Bob Mottram 2021-01-11 22:27:57 +00:00
parent 3c1314d4b4
commit 1bb4eab631
8 changed files with 31 additions and 4 deletions

View File

@ -903,6 +903,7 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
'png': 'image/png', 'png': 'image/png',
'jpeg': 'image/jpeg', 'jpeg': 'image/jpeg',
'gif': 'image/gif', 'gif': 'image/gif',
'svg': 'image/svg+xml',
'webp': 'image/webp', 'webp': 'image/webp',
'avif': 'image/avif', 'avif': 'image/avif',
'mp4': 'video/mp4', 'mp4': 'video/mp4',

View File

@ -290,6 +290,7 @@ class PubServer(BaseHTTPRequestHandler):
if path.endswith('.png') or \ if path.endswith('.png') or \
path.endswith('.jpg') or \ path.endswith('.jpg') or \
path.endswith('.gif') or \ path.endswith('.gif') or \
path.endswith('.svg') or \
path.endswith('.avif') or \ path.endswith('.avif') or \
path.endswith('.webp'): path.endswith('.webp'):
return True return True
@ -2865,6 +2866,8 @@ class PubServer(BaseHTTPRequestHandler):
mediaFilename = mediaFilenameBase + '.jpg' mediaFilename = mediaFilenameBase + '.jpg'
if self.headers['Content-type'].endswith('gif'): if self.headers['Content-type'].endswith('gif'):
mediaFilename = mediaFilenameBase + '.gif' mediaFilename = mediaFilenameBase + '.gif'
if self.headers['Content-type'].endswith('svg+xml'):
mediaFilename = mediaFilenameBase + '.svg'
if self.headers['Content-type'].endswith('webp'): if self.headers['Content-type'].endswith('webp'):
mediaFilename = mediaFilenameBase + '.webp' mediaFilename = mediaFilenameBase + '.webp'
if self.headers['Content-type'].endswith('avif'): if self.headers['Content-type'].endswith('avif'):
@ -5376,6 +5379,8 @@ class PubServer(BaseHTTPRequestHandler):
mediaImageType = 'webp' mediaImageType = 'webp'
elif emojiFilename.endswith('.avif'): elif emojiFilename.endswith('.avif'):
mediaImageType = 'avif' mediaImageType = 'avif'
elif emojiFilename.endswith('.svg'):
mediaImageType = 'svg+xml'
else: else:
mediaImageType = 'gif' mediaImageType = 'gif'
with open(emojiFilename, 'rb') as avFile: with open(emojiFilename, 'rb') as avFile:
@ -9326,6 +9331,8 @@ class PubServer(BaseHTTPRequestHandler):
mediaFileType = 'webp' mediaFileType = 'webp'
elif mediaFilename.endswith('.avif'): elif mediaFilename.endswith('.avif'):
mediaFileType = 'avif' mediaFileType = 'avif'
elif mediaFilename.endswith('.svg'):
mediaFileType = 'svg+xml'
else: else:
mediaFileType = 'gif' mediaFileType = 'gif'
with open(mediaFilename, 'rb') as avFile: with open(mediaFilename, 'rb') as avFile:
@ -9384,6 +9391,8 @@ class PubServer(BaseHTTPRequestHandler):
mediaImageType = 'gif' mediaImageType = 'gif'
elif avatarFile.endswith('.avif'): elif avatarFile.endswith('.avif'):
mediaImageType = 'avif' mediaImageType = 'avif'
elif avatarFile.endswith('.svg'):
mediaImageType = 'svg+xml'
else: else:
mediaImageType = 'webp' mediaImageType = 'webp'
with open(avatarFilename, 'rb') as avFile: with open(avatarFilename, 'rb') as avFile:
@ -10310,6 +10319,7 @@ class PubServer(BaseHTTPRequestHandler):
# image on login screen or qrcode # image on login screen or qrcode
if self.path == '/login.png' or \ if self.path == '/login.png' or \
self.path == '/login.gif' or \ self.path == '/login.gif' or \
self.path == '/login.svg' or \
self.path == '/login.webp' or \ self.path == '/login.webp' or \
self.path == '/login.avif' or \ self.path == '/login.avif' or \
self.path == '/login.jpeg' or \ self.path == '/login.jpeg' or \
@ -11910,6 +11920,7 @@ class PubServer(BaseHTTPRequestHandler):
filename.endswith('.jpg') or \ filename.endswith('.jpg') or \
filename.endswith('.webp') or \ filename.endswith('.webp') or \
filename.endswith('.avif') or \ filename.endswith('.avif') or \
filename.endswith('.svg') or \
filename.endswith('.gif'): filename.endswith('.gif'):
postImageFilename = filename.replace('.temp', '') postImageFilename = filename.replace('.temp', '')
print('Removing metadata from ' + postImageFilename) print('Removing metadata from ' + postImageFilename)

View File

@ -134,6 +134,7 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str,
extensions = { extensions = {
"jpeg": "jpg", "jpeg": "jpg",
"gif": "gif", "gif": "gif",
"svg": "svg",
"webp": "webp", "webp": "webp",
"avif": "avif", "avif": "avif",
"audio/mpeg": "mp3", "audio/mpeg": "mp3",

View File

@ -60,8 +60,9 @@ def setProfileImage(baseDir: str, httpPrefix: str, nickname: str, domain: str,
if not (imageFilename.endswith('.png') or if not (imageFilename.endswith('.png') or
imageFilename.endswith('.jpg') or imageFilename.endswith('.jpg') or
imageFilename.endswith('.jpeg') or imageFilename.endswith('.jpeg') or
imageFilename.endswith('.svg') or
imageFilename.endswith('.gif')): imageFilename.endswith('.gif')):
print('Profile image must be png, jpg or gif format') print('Profile image must be png, jpg, gif or svg format')
return False return False
if imageFilename.startswith('~/'): if imageFilename.startswith('~/'):
@ -95,6 +96,9 @@ def setProfileImage(baseDir: str, httpPrefix: str, nickname: str, domain: str,
if imageFilename.endswith('.gif'): if imageFilename.endswith('.gif'):
mediaType = 'image/gif' mediaType = 'image/gif'
iconFilename = iconFilenameBase + '.gif' iconFilename = iconFilenameBase + '.gif'
if imageFilename.endswith('.svg'):
mediaType = 'image/svg+xml'
iconFilename = iconFilenameBase + '.svg'
profileFilename = baseDir + '/accounts/' + handle + '/' + iconFilename profileFilename = baseDir + '/accounts/' + handle + '/' + iconFilename
personJson = loadJson(personFilename) personJson = loadJson(personFilename)
@ -591,7 +595,7 @@ def personLookup(domain: str, path: str, baseDir: str) -> {}:
else: else:
notPersonLookup = ('/inbox', '/outbox', '/outboxarchive', notPersonLookup = ('/inbox', '/outbox', '/outboxarchive',
'/followers', '/following', '/featured', '/followers', '/following', '/featured',
'.png', '.jpg', '.gif', '.mpv') '.png', '.jpg', '.gif', '.svg', '.mpv')
for ending in notPersonLookup: for ending in notPersonLookup:
if path.endswith(ending): if path.endswith(ending):
return None return None

View File

@ -180,8 +180,9 @@ def postImage(session, attachImageFilename: str, federationList: [],
if not (attachImageFilename.endswith('.jpg') or if not (attachImageFilename.endswith('.jpg') or
attachImageFilename.endswith('.jpeg') or attachImageFilename.endswith('.jpeg') or
attachImageFilename.endswith('.png') or attachImageFilename.endswith('.png') or
attachImageFilename.endswith('.svg') or
attachImageFilename.endswith('.gif')): attachImageFilename.endswith('.gif')):
print('Image must be png, jpg, or gif') print('Image must be png, jpg, gif or svg')
return None return None
if not os.path.isfile(attachImageFilename): if not os.path.isfile(attachImageFilename):
print('Image not found: ' + attachImageFilename) print('Image not found: ' + attachImageFilename)
@ -191,6 +192,8 @@ def postImage(session, attachImageFilename: str, federationList: [],
contentType = 'image/png' contentType = 'image/png'
if attachImageFilename.endswith('.gif'): if attachImageFilename.endswith('.gif'):
contentType = 'image/gif' contentType = 'image/gif'
if attachImageFilename.endswith('.svg'):
contentType = 'image/svg+xml'
headers['Content-type'] = contentType headers['Content-type'] = contentType
with open(attachImageFilename, 'rb') as avFile: with open(attachImageFilename, 'rb') as avFile:

View File

@ -133,7 +133,7 @@ def isEditor(baseDir: str, nickname: str) -> bool:
def getImageExtensions() -> []: def getImageExtensions() -> []:
"""Returns a list of the possible image file extensions """Returns a list of the possible image file extensions
""" """
return ('png', 'jpg', 'jpeg', 'gif', 'webp', 'avif') return ('png', 'jpg', 'jpeg', 'gif', 'webp', 'avif', 'svg')
def getVideoExtensions() -> []: def getVideoExtensions() -> []:
@ -1725,6 +1725,7 @@ def mediaFileMimeType(filename: str) -> str:
'jpg': 'image/jpeg', 'jpg': 'image/jpeg',
'jpeg': 'image/jpeg', 'jpeg': 'image/jpeg',
'gif': 'image/gif', 'gif': 'image/gif',
'svg': 'image/svg+xml',
'webp': 'image/webp', 'webp': 'image/webp',
'avif': 'image/avif', 'avif': 'image/avif',
'mp3': 'audio/mpeg', 'mp3': 'audio/mpeg',

View File

@ -61,6 +61,9 @@ def htmlLogin(cssCache: {}, translate: {},
elif os.path.isfile(baseDir + '/accounts/login.gif'): elif os.path.isfile(baseDir + '/accounts/login.gif'):
loginImage = 'login.gif' loginImage = 'login.gif'
loginImageFilename = baseDir + '/accounts/' + loginImage loginImageFilename = baseDir + '/accounts/' + loginImage
elif os.path.isfile(baseDir + '/accounts/login.svg'):
loginImage = 'login.svg'
loginImageFilename = baseDir + '/accounts/' + loginImage
elif os.path.isfile(baseDir + '/accounts/login.webp'): elif os.path.isfile(baseDir + '/accounts/login.webp'):
loginImage = 'login.webp' loginImage = 'login.webp'
loginImageFilename = baseDir + '/accounts/' + loginImage loginImageFilename = baseDir + '/accounts/' + loginImage

View File

@ -295,6 +295,7 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str,
'jpg': 'jpeg', 'jpg': 'jpeg',
'jpeg': 'jpeg', 'jpeg': 'jpeg',
'gif': 'gif', 'gif': 'gif',
'svg': 'svg+xml',
'webp': 'webp', 'webp': 'webp',
'avif': 'avif' 'avif': 'avif'
} }
@ -653,12 +654,14 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {},
mediaType == 'image/jpeg' or \ mediaType == 'image/jpeg' or \
mediaType == 'image/webp' or \ mediaType == 'image/webp' or \
mediaType == 'image/avif' or \ mediaType == 'image/avif' or \
mediaType == 'image/svg+xml' or \
mediaType == 'image/gif': mediaType == 'image/gif':
if attach['url'].endswith('.png') or \ if attach['url'].endswith('.png') or \
attach['url'].endswith('.jpg') or \ attach['url'].endswith('.jpg') or \
attach['url'].endswith('.jpeg') or \ attach['url'].endswith('.jpeg') or \
attach['url'].endswith('.webp') or \ attach['url'].endswith('.webp') or \
attach['url'].endswith('.avif') or \ attach['url'].endswith('.avif') or \
attach['url'].endswith('.svg') or \
attach['url'].endswith('.gif'): attach['url'].endswith('.gif'):
if attachmentCtr > 0: if attachmentCtr > 0:
attachmentStr += '<br>' attachmentStr += '<br>'