tubelobi.blogg.se

Photo collage maker
Photo collage maker












photo collage maker

llage_nfig(width=collage_width, height=collage_height) "Number of Columns", "Enter the number of columns:"Ĭollage_width = llage_size * cols // 2Ĭollage_height = llage_size * rows // 2 Rows = simpledialog.askinteger( "Number of Rows", "Enter the number of rows:") Initialize x and y offset to zero, so you can keep track of the position offsets for arranging images in rows and columns. Set the collage's width and height to take half of the specified collage size. Clear all the items and ask the user for the desired number of rows and columns via a file dialog box. Return image.resize((new_width, new_height))ĭefine a method, update_canvas. New_width = int(new_height * aspect_ratio) New_height = int(new_width / aspect_ratio) Use Pillow's resize method to return a resized image using the calculated parameters. Similarly, calculate the corresponding width. If the aspect ratio is less than one, set the new height to be half of the collage's height. Calculate the corresponding new height while maintaining the aspect ratio. If it is more than one, set the new width to be half of the collage's width. Get the width and height of the image and calculate its aspect ratio. Self.image_refs.append(ImageTk.PhotoImage(resized_image))ĭefine a method, resize_image.

photo collage maker

"Number of Images", "Enter the number of images:"įile_paths = filedialog.askopenfilenames(įiletypes=įor i in range(min(num_images, len(file_paths))): Add this to the image_refs list and call the update_canvas method. Once the user has selected one or more images, open each one with Pillow's Image.open() method.Ĭall the resize_image method and create a Tkinter-compatible PhotoImage. If the user provided a valid number, open a file dialog box that only allows the user to select image files. Create a dialog box that prompts the user to enter the number of images for the collage. For each item, find the coordinates and add them to the list.įor item in llage_canvas.find_all():ĭefine a method, add_images. Clear the image_positions list and iterate over all canvas items. def on_release (self, event):ĭefine a method, update_image_positions.

#Photo collage maker update

Call the update_image_positions to update the positions of all images on the canvas after the user drags and releases it. Clear the reference to the image the user was dragging along with its coordinates. llage_canvas.move(self.drag_data, delta_x, delta_y)ĭefine a method, on_release. Store the updated coordinates of the image under the x and y keys of the drag_data dictionary. Calculate the horizontal and the vertical distance the user moved the mouse during dragging and update the position of the image accordingly. Self.drag_data = llage_canvas.find_closest(event.x, event.y)ĭefine a method, on_drag. You will use this to calculate the distance the user moves the mouse during dragging. Store the x and y coordinates of the mouse click. Retrieve the closest canvas item from the location where the user clicks the mouse and store it under the item key of the drag_data dictionary. llage_canvas.bind( "", self.on_release)ĭefine a method, on_press. Define three event handlers to respond to the selection, dragging, and releasing of images. Initialize image_positions to store the positions of images on the canvas.














Photo collage maker