def _savePreview(self,image,sourcePath:str,isCustom:bool): fileName = FileFolderService.getFileName(sourcePath) if isCustom: fileName = CfgService.get(CfgKey.GREENSCREEN_CUSTOM_BACKGROUND_PREVIEW_FILENAME)+fileName filePath = os.path.join(GreenscreenBackgroundService.getCustomBackgroundPath(), fileName) else: filePath = os.path.join(self._getTempPath(), fileName) windowSize = self.globalVariable.getWindowSize() preview = image.resize((windowSize.width(),windowSize.height())) preview.save(filePath) return filePath
def displayBackground_image(uuid,number): print("PictureHash: "+number) if uuid is None: abort(404) authorizade = ServerDbSevice.getBackgroundUploadAuthorization(uuid) if authorizade is None: abort(404) filePath = GreenscreenBackgroundService.getCustomFilePathWithName(authorizade["targetPath"],uuid) imageAsByte = FileFolderService.readImage(filePath) return send_file(io.BytesIO(imageAsByte), as_attachment=True, attachment_filename=FileFolderService.getFileName(filePath), mimetype='image/'+FileFolderService.getFileType(filePath).replace("\.",""))
def getCustomFilePathWithName(customBackgroundFolder:str,uuid:str, fileName:str = None): FileFolderService.createFolderIfNotExist(customBackgroundFolder) newFileName = uuid existingFileNames = [] for fileUrl in FileFolderService.getFolderContentFiles(customBackgroundFolder): existingFileName = FileFolderService.getFileName(fileUrl) if existingFileName.startswith( newFileName ): existingFileNames.append(fileUrl) if fileName is None: if len(existingFileNames)> 0: newFileNameWithIndex = newFileName+"_"+str(len(existingFileNames)) for existingFileUrl in existingFileNames: existingFileName = FileFolderService.getFileName(existingFileUrl) if existingFileName.startswith(newFileNameWithIndex): return existingFileUrl return None else: type = FileFolderService.getFileType(fileName) return os.path.join(customBackgroundFolder,newFileName+"_"+str(len(existingFileNames)+1)+type)