def execute_temp(): """ Function that applies the changes to the file indicated by the filepath, It first finds the values used for the changes, then applies them in the order: 1. Crop the image 2. Shift the hue of the image 3. Resize the image 4. Any other post-processing effects 5. Save the image """ # Update filename if not custom_outpath.get(): update_outpath(file_io_input_path.get()) # Find changes cur_image = mi.open_image(file_io_input_path.get()) crop_point1 = (int(tool_crop_top.get()), int(tool_crop_top2.get())) crop_point2 = (int(tool_crop_bottom.get()), int(tool_crop_bottom2.get())) hue_shift = int(tool_hue_shift_hue.get()) sat_shift = int(tool_hue_shift_sat.get()) lum_shift = int(tool_hue_shift_lum.get()) resize_x = float(tool_resize_horizontal.get()) resize_y = float(tool_resize_vertical.get()) path = file_io_output_path.get() # Apply changes print("Cropping Image") cur_image = ei.crop(cur_image, crop_point1, crop_point2) print("Changing Colors") cur_image = ei.shift_hsl(cur_image, hue_shift, sat_shift, lum_shift) print("Resizing Image") cur_image = ei.resize(cur_image, (resize_x, resize_y)) # Apply effects if subpixel_activated.get(): print("Applying effects") cur_image = ei.subpixel_conversion(cur_image) print("Saving Temp File") path = "./temp/" + pl.Path(path).name mi.save_image(cur_image, path) file_io_input_path.delete(0, tk.END) file_io_input_path.insert(0, path) # Change to default values of crop cur_image = mi.open_image(file_io_input_path.get()) width, height = cur_image.size tool_crop_bottom.delete(0, tk.END) tool_crop_bottom.insert(0, width) tool_crop_bottom2.delete(0, tk.END) tool_crop_bottom2.insert(0, height)
def browse_file_in(): """ Function that opens a file browse dialogue then changes the input entry box and output entry box accordingly """ # File dialogue filetypes = file_io_input_ext_entry.get().replace(":", " ") path = filedialog.askopenfilename( filetypes=(("Image Files", filetypes), ("All files", "*"))) # Add the readout from the other entry # Change the input boxes to reflect loaded path file_io_input_path.delete(0, tk.END) file_io_input_path.insert(0, path) # Change to default values of crop cur_image = mi.open_image(file_io_input_path.get()) width, height = cur_image.size tool_crop_bottom.delete(0, tk.END) tool_crop_bottom.insert(0, width) tool_crop_bottom2.delete(0, tk.END) tool_crop_bottom2.insert(0, height) if not custom_outpath.get(): update_outpath(path) print("File Loaded")
def getendpoint(eventorigin): global x1, y1 x1 = eventorigin.x y1 = eventorigin.y print("Point 2:", x1, y1) gui_win.unbind("<Button 1>") img.configure(cursor="") # Do the crop thing print("Applying Crop") point_1 = (x0, y0) point_2 = (x1, y1) temp_image = mi.open_image(file_io_input_path.get()) temp_image = ei.crop(temp_image, point_1, point_2) path = "./temp/" + pl.Path(file_io_input_path.get()).name mi.save_image(temp_image, path) file_io_input_path.delete(0, tk.END) file_io_input_path.insert(0, path) # Change to default values of crop cur_image = mi.open_image(file_io_input_path.get()) width, height = cur_image.size tool_crop_bottom.delete(0, tk.END) tool_crop_bottom.insert(0, width) tool_crop_bottom2.delete(0, tk.END) tool_crop_bottom2.insert(0, height) new_image = mi.open_image("./temp/" + pl.Path(file_io_input_path.get()).name) new_image = ImageTk.PhotoImage(new_image) img.configure(image=new_image) img.image = new_image
def execute_file(): """ Function that applies the changes to the file indicated by the filepath, It first finds the values used for the changes, then applies them in the order: 1. Crop the image 2. Shift the hue of the image 3. Resize the image 4. Any other post-processing effects 5. Save the image """ # Update filename if not custom_outpath: update_outpath(file_io_input_path.get()) # Find changes cur_image = mi.open_image(file_io_input_path.get()) crop_point1 = (int(tool_crop_top.get()), int(tool_crop_top2.get())) crop_point2 = (int(tool_crop_bottom.get()), int(tool_crop_bottom2.get())) hue_shift = int(tool_hue_shift_hue.get()) sat_shift = int(tool_hue_shift_sat.get()) lum_shift = int(tool_hue_shift_lum.get()) resize_x = float(tool_resize_horizontal.get()) resize_y = float(tool_resize_vertical.get()) output = file_io_output_path.get() # Apply changes print("Cropping Image") cur_image = ei.crop(cur_image, crop_point1, crop_point2) print("Changing Colors") cur_image = ei.shift_hsl(cur_image, hue_shift, sat_shift, lum_shift) print("Resizing Image") cur_image = ei.resize(cur_image, (resize_x, resize_y)) # Apply effects if subpixel_activated.get(): print("Applying effects") cur_image = ei.subpixel_conversion(cur_image) # Save image print("Saving Image") if ".maxpg" in output: codec.save_as_codec(cur_image, output) else: mi.save_image(cur_image, output)
def open_preview(): """ Function to open a preview window of the image indicated from the filepath """ filepath = pl.Path(file_io_input_path.get()) prev_win = tk.Toplevel() prev_win.wm_title(filepath.name) prev_win.resizable(False, False) # Find changes cur_image = mi.open_image(file_io_input_path.get()) crop_point1 = (int(tool_crop_top.get()), int(tool_crop_top2.get())) crop_point2 = (int(tool_crop_bottom.get()), int(tool_crop_bottom2.get())) hue_shift = int(tool_hue_shift_hue.get()) sat_shift = int(tool_hue_shift_sat.get()) lum_shift = int(tool_hue_shift_lum.get()) resize_x = float(tool_resize_horizontal.get()) resize_y = float(tool_resize_vertical.get()) output = file_io_output_path.get() # Apply changes print("Cropping Image") cur_image = ei.crop(cur_image, crop_point1, crop_point2) print("Changing Colors") cur_image = ei.shift_hsl(cur_image, hue_shift, sat_shift, lum_shift) print("Resizing Image") cur_image = ei.resize(cur_image, (resize_x, resize_y)) # Apply effects if subpixel_activated.get(): print("Applying effects") cur_image = ei.subpixel_conversion(cur_image) pic = ImageTk.PhotoImage(cur_image) img = ttk.Label(prev_win, image=pic) img.image = pic img.grid(row=0, column=0)
def open_GUI(): def getorigin(eventorigin): global x0, y0 x0 = eventorigin.x y0 = eventorigin.y print("Point 1:", x0, y0) gui_win.bind("<Button 1>", getendpoint) def getendpoint(eventorigin): global x1, y1 x1 = eventorigin.x y1 = eventorigin.y print("Point 2:", x1, y1) gui_win.unbind("<Button 1>") img.configure(cursor="") # Do the crop thing print("Applying Crop") point_1 = (x0, y0) point_2 = (x1, y1) temp_image = mi.open_image(file_io_input_path.get()) temp_image = ei.crop(temp_image, point_1, point_2) path = "./temp/" + pl.Path(file_io_input_path.get()).name mi.save_image(temp_image, path) file_io_input_path.delete(0, tk.END) file_io_input_path.insert(0, path) # Change to default values of crop cur_image = mi.open_image(file_io_input_path.get()) width, height = cur_image.size tool_crop_bottom.delete(0, tk.END) tool_crop_bottom.insert(0, width) tool_crop_bottom2.delete(0, tk.END) tool_crop_bottom2.insert(0, height) new_image = mi.open_image("./temp/" + pl.Path(file_io_input_path.get()).name) new_image = ImageTk.PhotoImage(new_image) img.configure(image=new_image) img.image = new_image def visual_crop(): print("Cropping") img.configure(cursor="crosshair") gui_win.bind("<Button 1>", getorigin) # ----- WINDOW ----- # Setup window filepath = pl.Path(file_io_input_path.get()) gui_win = tk.Toplevel() gui_win.wm_title(filepath.name) gui_win.resizable(False, False) gui_win.iconbitmap("./images/favicon.ico") # ----- FRAMES ----- # Define the Frames for each section toolbar = ttk.Frame(gui_win, relief="raised") toolbar.grid(row=0, column=0) # ----- WIDGETS ----- # Define toolbar buttons crop_icon = mi.open_image("./images/crop_icon.png") crop_image = ImageTk.PhotoImage(crop_icon) gui_tool_crop_button = ttk.Button(toolbar, image=crop_image, command=visual_crop) gui_tool_crop_button.image = crop_image gui_tool_crop_button.grid(row=0, column=0) # Define image display cur_image = mi.open_image(file_io_input_path.get()) main_pic = ImageTk.PhotoImage(cur_image) img = ttk.Label(gui_win, image=main_pic) img.image = main_pic img.grid(row=1, column=0)
pixmap = pic.load() new_pixmap = new_pic.load() for i in range(pic.size[0]): # for every col of the original image for j in range(pic.size[1]): # For every row of the original image real_x = i * 3 real_y = j * 3 color = pixmap[i, j] for k in range(3): # for every color for l in range(3): # for every pixel of color if k == 0: new_pixmap[real_x + k, real_y + l] = (color[0], 0, 0) elif k == 1: new_pixmap[real_x + k, real_y + l] = (0, color[1], 0) elif k == 2: new_pixmap[real_x + k, real_y + l] = (0, 0, color[2]) return new_pic if __name__ == '__main__': cur_image = mi.open_image("C:\\Users\\DarkA\\Desktop\\Capture.PNG") # shift_hsl(cur_image, 0, 10, 0) # crop(cur_image, (0, 0), (75, 100)) # cur_image = resize(cur_image, (1.0, 1.0)) cur_image = subpixel_conversion(cur_image) cur_image.show()
def save_as_codec(pic: Image, filename: str) -> str: """ A function to save a picture to a filename. :param pic: The picture as a Image. :param filename: The filename as a string *without* the file extension. :return The filename with extension. """ binary = encode_image(pic) with open(filename, "wb+") as f: f.write(binary) print("Exported Image") return filename if __name__ == '__main__': cur_image = mi.open_image("RGB_24bits_palette_sample_image.jpg") print(generate_header(cur_image)) # encoded = encode_image(cur_image) # save_as_codec(cur_image, "bank.maxpg") # mi.save_image(decode_image(encoded), "codec.jpg") # datetime.fromtimestamp(time.time()).strftime('%c') # cur_image = decode_image("first_text.maxpg") # cur_image = decode_image("first_text.maxpg")