Option to set the profile background image

master
Bob Mottram 2019-07-12 15:40:03 +01:00
parent 1cfe63022f
commit befc991fbf
2 changed files with 20 additions and 4 deletions

View File

@ -137,6 +137,8 @@ parser.add_argument("--cw", type=str2bool, nargs='?', \
help="Default capabilities don't allow posts without content warnings")
parser.add_argument('--icon','--avatar', dest='avatar', type=str,default=None, \
help='Set the avatar filename for an account')
parser.add_argument('--image','--background', dest='backgroundImage', type=str,default=None, \
help='Set the profile background image for an account')
args = parser.parse_args()
debug=False
@ -409,12 +411,26 @@ if args.avatar:
print('Specify a nickname with --nickname [name]')
sys.exit()
if setProfileImage(baseDir,httpPrefix,args.nickname,domain, \
port,args.avatar,'avatar'):
port,args.avatar,'avatar','128x128'):
print('Avatar added for '+args.nickname)
else:
print('Avatar was not added for '+args.nickname)
sys.exit()
if args.backgroundImage:
if not os.path.isfile(args.backgroundImage):
print(args.backgroundImage+' is not an image filename')
sys.exit()
if not args.nickname:
print('Specify a nickname with --nickname [name]')
sys.exit()
if setProfileImage(baseDir,httpPrefix,args.nickname,domain, \
port,args.backgroundImage,'background','256x256'):
print('Background image added for '+args.nickname)
else:
print('Background image was not added for '+args.nickname)
sys.exit()
if federationList:
print('Federating with: '+str(federationList))

View File

@ -26,7 +26,7 @@ def generateRSAKey() -> (str,str):
return privateKeyPem,publicKeyPem
def setProfileImage(baseDir: str,httpPrefix :str,nickname: str,domain: str, \
port :int,imageFilename: str,imageType :str) -> bool:
port :int,imageFilename: str,imageType :str,resolution :str) -> bool:
"""Saves the given image file as an avatar or background
image for the given person
"""
@ -80,7 +80,7 @@ def setProfileImage(baseDir: str,httpPrefix :str,nickname: str,domain: str, \
with open(personFilename, 'w') as fp:
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
cmd = '/usr/bin/convert '+imageFilename+' -size 128x128 -quality 50 '+profileFilename
cmd = '/usr/bin/convert '+imageFilename+' -size '+resolution+' -quality 50 '+profileFilename
subprocess.call(cmd, shell=True)
return True
return False