def saveSiteDetail(formData, imageData): with open(os.path.join(DATABASE["location"], "site-detail.json"), 'w') as form: json.dump(formData, form) for image in imageData: if imageData[image]: img_obj = HandleImage.load(imageData[image]) img_obj = HandleImage.reduce_size(img_obj) HandleImage.save( img_obj, os.path.join(DATABASE["image-loc"], DATABASE["images"][image]))
def add(image): databaseLoc = os.path.join(DATABASE["location"], DATABASE["gallery-loc"]) imgLoc = os.path.join(DATABASE["image-loc"], DATABASE["gallery-loc"]) img = HandleImage.load(image) img = HandleImage.reduce_size(img) jsonData = loadJSON(databaseLoc, "gallery-list.json")["galleries"] newId = 1 if len(jsonData): newId = int(jsonData[len(jsonData) - 1]["id"]) + 1 newJson = {"id": str(newId), "caption": "dummy caption"} jsonData.append(newJson) with open(os.path.join(databaseLoc, "gallery-list.json"), "w") as f: json.dump({"galleries": jsonData}, f) HandleImage.save(img, os.path.join(imgLoc, str(newId) + ".jpg"))
def add(image): databaseLoc = os.path.join(DATABASE["location"], DATABASE["gallery-loc"]) imgLoc = os.path.join(DATABASE["image-loc"], DATABASE["gallery-loc"], "more") img = HandleImage.load(image) img = HandleImage.reduce_size(img) jsonData = loadJSON(databaseLoc, "more-gallery.json") galleries = jsonData["galleries"] newId = 1 if len(jsonData["galleries"]): newId = int(galleries[len(galleries) - 1]["id"]) + 1 newJson = {"id": str(newId), "caption": "dummy caption"} galleries.append(newJson) jsonData["galleries"] = galleries with open(os.path.join(databaseLoc, "more-gallery.json"), "w") as f: json.dump(jsonData, f) HandleImage.save(img, os.path.join(imgLoc, str(newId) + ".jpg"))
def saveFavIcon(): rootDir = os.path.normpath(currentDir + "/output") profImage = os.path.normpath(currentDir + "/output/img/about-profile.jpg") if os.path.exists(profImage): HandleImage.faviconGenerator(profImage, rootDir) # create ieconfig.xml file with open(os.path.join(rootDir, "ieconfig.xml"), "w") as f: text = """<?xml version="1.0" encoding="utf-8"?> <browserconfig> <msapplication> <tile> <square70x70logo src="/smalltile.png"/> <square150x150logo src="/mediumtile.png"/> <wide310x150logo src="/widetile.png"/> <square310x310logo src="/largetile.png"/> <TileColor>#009900</TileColor> </tile> </msapplication> </browserconfig>""" f.write(text)
def uploadImage(postId, image): imageDir = os.path.join(DATABASE["posts"], "images", postId) imgIds = PostManager.getImageIds(postId) newId = "1" if imgIds: newId = max(imgIds) + 1 # last_id + 1 img = HandleImage.load(image) img = HandleImage.reduce_size(img) # check if the image is in gif format imgFormat = "" if img.format != 'GIF': imageLoc = os.path.join(imageDir, postId + "-" + str(newId) + ".jpg") imgFormat = "jpg" else: imageLoc = os.path.join(imageDir, postId + "-" + str(newId) + ".gif") imgFormat = "gif" HandleImage.save(img, imageLoc) return str(newId), imgFormat
def save(formData, imageData): loc = os.path.join(DATABASE["location"], DATABASE["service-loc"]) img_loc = os.path.join(DATABASE["image-loc"], DATABASE["service-loc"]) serviceFiles = Services.getServiceFiles() for serviceFile in serviceFiles: nameKey = "name-" + serviceFile.split(".")[0] descriptionKey = "description-" + serviceFile.split(".")[0] imageKey = "image-" + serviceFile.split(".")[0] jsonData = loadJSON(loc, serviceFile) jsonData["name"] = formData[nameKey] jsonData["description"] = formData[descriptionKey] with open(os.path.join(loc, serviceFile), "w") as f: json.dump(jsonData, f) if imageData[imageKey]: img_obj = Image.open(imageData[imageKey]) HandleImage.save( img_obj, os.path.join(img_loc, serviceFile.split(".")[0] + ".png"))
def savePageInfo(postId, formData, imageData): databaseDir = os.path.join(DATABASE["location"], DATABASE["post-loc"]) imageLoc = os.path.join(DATABASE["posts"], "images", postId, postId + ".jpg") posts = Posts.getPosts() newPosts = [] for post in posts: if post['id'] == postId: post["title"] = formData["title"] post["description"] = formData["description"] post["category"] = formData["category"] post["keywords"] = formData["keywords"].strip().split(",") newPosts.append(post) with open(os.path.join(databaseDir, "post-list.json"), "w") as f: json.dump({"posts": newPosts}, f) if imageData["image"]: img = HandleImage.load(imageData["image"]) img = HandleImage.reduce_size(img) HandleImage.save(img, imageLoc)