def save_image(image: Cimpl.Image) -> None: """ Author: Ibrahim Kasim, Himanshu Singh RETURNS None and prompts the user to select a filename to save image as image is a Cimpl.Image object >>> save_image(Cimpl.load_image(Cimpl.choose_file())) """ print("Select your image's save directory") Cimpl.save_as(image)
def save_image(image: Cimpl.Image, filename: str) -> None: """ Authors: Zakaria Ismail, Yanglong Liu RETURNS None and saves image to the directory using information from filename image is a Cimpl.Image object that is going to be saved filename is a str that defines the image's filename when saved >>> save_image(Cimpl.load_image(Cimpl.choose_file()), 'filename.png') None """ Cimpl.save_as(image, filename)
def combine(r_img: Cimpl.Image, g_img: Cimpl.Image, b_img: Cimpl.Image) -> Cimpl.Image: """ Author: Zakaria Ismail RETURNS an ImageObject where three Cimpl.Image objects are passed. Combines the color channels of the three arguments. >>> Cimpl.show(combine(Cimpl.load_image('red_image.png'), Cimpl.load_image('green_image.png'), Cimpl.load_image('blue_image.png')) -> Returns a Cimpl.Image object """ base = Cimpl.copy(r_img) for x, y, (r, g, b) in base: g_r, g_g, g_b = Cimpl.get_color(g_img, x, y) b_r, b_g, b_b = Cimpl.get_color(b_img, x, y) color = Cimpl.create_color(compute_sum(r, g_r, b_r), compute_sum(g, g_g, b_g), compute_sum(b, g_b, b_b)) Cimpl.set_color(base, x, y, color) Cimpl.save_as(base, 'combined_image.png') return base
elif selection == '4': print("INFO: This may take a while, please be patient. Running simulation....") wildcardFrames = "images/frame*.png" count, check = 0, 0 check_directory() remove_old_frames(wildcardFrames) originalUpdatedStateList = deepcopy(updatedStateList) # SIMULATION BEGINS --------------------------------------------------- simLoop = True while simLoop == True and count <= maxFrames: pixelStateList = deepcopy(updatedStateList) refresh_board(gameBoard, res, blockColor, updatedStateList) Cimpl.save_as(gameBoard, "images/frame" + str(count) + ".png") for scanY in range(height): for scanX in range(width): BLOCK = scan_block(scanX, scanY, width, height) liveCount = 0 for x, y in BLOCK: if x != None and y != None: if pixelStateList[y][x] == 1: liveCount += 1 if pixelStateList[scanY][scanX] == 0:
new_blue = int(new_blue, 2) #Create and Set color new_color = Cimpl.create_color(new_red, new_green, new_blue) Cimpl.set_color(img, x, y, new_color) #load image image = Cimpl.load_image(Cimpl.choose_file()) #Convert user input string to binary string = input("Input the text you would like to hide:") string = "*****" + string + '|||||' string_in_bin = text_to_bits(string) string_in_bin = list(string_in_bin) #calculate how many bits we can alter image_width = Cimpl.get_width(image) image_height = Cimpl.get_height(image) open_bits = image_width*image_height*3 #repeat string to cover entire image string_bin_length = len(string_in_bin) possible_repeat = open_bits//string_bin_length extended_string = string_in_bin * possible_repeat encrypt(image, extended_string) Cimpl.save_as(image, 'newpic.png') print("done")
string = '*****' + string + '|||||' string_in_bin = text_to_bits(string) string_in_bin = list(string_in_bin) #calculate how many bits we can alter image_width = Cimpl.get_width(image) image_height = Cimpl.get_height(image) open_bits = image_width*image_height*3 #repeat string to cover entire image string_bin_length = len(string_in_bin) possible_repeat = open_bits//string_bin_length extended_string = string_in_bin * possible_repeat encrypt(image, extended_string) filename = input('What would you like to name the encrypted photo:') + '.png' Cimpl.save_as(image, filename) print("The image has been encrypted\n\nThis program will restart in 5 seconds\n\n") time.sleep(5) if command == 'D' or command == 'd': #set variables last_bit = [] str1 = str() set_of_strings = [] #load image print('Please slect the image you would like to decrypt. The file dialog may be underneath another window') image = Cimpl.load_image(Cimpl.choose_file()) #start decryption process get_bin(image) list_to_string = ''.join(str(e) for e in last_bit) try: