Support for svg format images

merge-requests/8/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',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'svg': 'image/svg+xml',
'webp': 'image/webp',
'avif': 'image/avif',
'mp4': 'video/mp4',

View File

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

View File

@ -134,6 +134,7 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str,
extensions = {
"jpeg": "jpg",
"gif": "gif",
"svg": "svg",
"webp": "webp",
"avif": "avif",
"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
imageFilename.endswith('.jpg') or
imageFilename.endswith('.jpeg') or
imageFilename.endswith('.svg') or
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
if imageFilename.startswith('~/'):
@ -95,6 +96,9 @@ def setProfileImage(baseDir: str, httpPrefix: str, nickname: str, domain: str,
if imageFilename.endswith('.gif'):
mediaType = 'image/gif'
iconFilename = iconFilenameBase + '.gif'
if imageFilename.endswith('.svg'):
mediaType = 'image/svg+xml'
iconFilename = iconFilenameBase + '.svg'
profileFilename = baseDir + '/accounts/' + handle + '/' + iconFilename
personJson = loadJson(personFilename)
@ -591,7 +595,7 @@ def personLookup(domain: str, path: str, baseDir: str) -> {}:
else:
notPersonLookup = ('/inbox', '/outbox', '/outboxarchive',
'/followers', '/following', '/featured',
'.png', '.jpg', '.gif', '.mpv')
'.png', '.jpg', '.gif', '.svg', '.mpv')
for ending in notPersonLookup:
if path.endswith(ending):
return None

View File

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

View File

@ -133,7 +133,7 @@ def isEditor(baseDir: str, nickname: str) -> bool:
def getImageExtensions() -> []:
"""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() -> []:
@ -1725,6 +1725,7 @@ def mediaFileMimeType(filename: str) -> str:
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'svg': 'image/svg+xml',
'webp': 'image/webp',
'avif': 'image/avif',
'mp3': 'audio/mpeg',

View File

@ -61,6 +61,9 @@ def htmlLogin(cssCache: {}, translate: {},
elif os.path.isfile(baseDir + '/accounts/login.gif'):
loginImage = 'login.gif'
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'):
loginImage = 'login.webp'
loginImageFilename = baseDir + '/accounts/' + loginImage

View File

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